Skip to content

Commit 4b77331

Browse files
mathstufdscho
authored andcommitted
clean: suggest using core.longPaths if paths are too long to remove
On Windows, git repositories may have extra files which need cleaned (e.g., a build directory) that may be arbitrarily deep. Suggest using `core.longPaths` if such situations are encountered. Fixes: #2715 Signed-off-by: Ben Boeckel <[email protected]>
1 parent 7bd3018 commit 4b77331

File tree

4 files changed

+17
-0
lines changed

4 files changed

+17
-0
lines changed

Documentation/config/advice.txt

+3
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,9 @@ advice.*::
118118
waitingForEditor::
119119
Print a message to the terminal whenever Git is waiting for
120120
editor input from the user.
121+
nameTooLong::
122+
Advice shown if a filepath operation is attempted where the
123+
path was too long.
121124
nestedTag::
122125
Advice shown if a user attempts to recursively tag a tag object.
123126
submoduleAlternateErrorStrategyDie::

advice.c

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ static struct {
4848
[ADVICE_GRAFT_FILE_DEPRECATED] = { "graftFileDeprecated", 1 },
4949
[ADVICE_IGNORED_HOOK] = { "ignoredHook", 1 },
5050
[ADVICE_IMPLICIT_IDENTITY] = { "implicitIdentity", 1 },
51+
[ADVICE_NAME_TOO_LONG] = { "nameTooLong", 1 },
5152
[ADVICE_NESTED_TAG] = { "nestedTag", 1 },
5253
[ADVICE_OBJECT_NAME_WARNING] = { "objectNameWarning", 1 },
5354
[ADVICE_PUSH_ALREADY_EXISTS] = { "pushAlreadyExists", 1 },

advice.h

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ struct string_list;
2626
ADVICE_GRAFT_FILE_DEPRECATED,
2727
ADVICE_IGNORED_HOOK,
2828
ADVICE_IMPLICIT_IDENTITY,
29+
ADVICE_NAME_TOO_LONG,
2930
ADVICE_NESTED_TAG,
3031
ADVICE_OBJECT_NAME_WARNING,
3132
ADVICE_PUSH_ALREADY_EXISTS,

builtin/clean.c

+12
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,9 @@ static int remove_dirs(struct strbuf *path, const char *prefix, int force_flag,
211211
quote_path(path->buf, prefix, &quoted, 0);
212212
errno = saved_errno;
213213
warning_errno(_(msg_warn_remove_failed), quoted.buf);
214+
if (saved_errno == ENAMETOOLONG) {
215+
advise_if_enabled(ADVICE_NAME_TOO_LONG, _("Setting `core.longPaths` may allow the deletion to succeed."));
216+
}
214217
*dir_gone = 0;
215218
}
216219
ret = res;
@@ -246,6 +249,9 @@ static int remove_dirs(struct strbuf *path, const char *prefix, int force_flag,
246249
quote_path(path->buf, prefix, &quoted, 0);
247250
errno = saved_errno;
248251
warning_errno(_(msg_warn_remove_failed), quoted.buf);
252+
if (saved_errno == ENAMETOOLONG) {
253+
advise_if_enabled(ADVICE_NAME_TOO_LONG, _("Setting `core.longPaths` may allow the deletion to succeed."));
254+
}
249255
*dir_gone = 0;
250256
ret = 1;
251257
}
@@ -289,6 +295,9 @@ static int remove_dirs(struct strbuf *path, const char *prefix, int force_flag,
289295
quote_path(path->buf, prefix, &quoted, 0);
290296
errno = saved_errno;
291297
warning_errno(_(msg_warn_remove_failed), quoted.buf);
298+
if (saved_errno == ENAMETOOLONG) {
299+
advise_if_enabled(ADVICE_NAME_TOO_LONG, _("Setting `core.longPaths` may allow the deletion to succeed."));
300+
}
292301
*dir_gone = 0;
293302
ret = 1;
294303
}
@@ -1108,6 +1117,9 @@ int cmd_clean(int argc, const char **argv, const char *prefix)
11081117
qname = quote_path(item->string, NULL, &buf, 0);
11091118
errno = saved_errno;
11101119
warning_errno(_(msg_warn_remove_failed), qname);
1120+
if (saved_errno == ENAMETOOLONG) {
1121+
advise_if_enabled(ADVICE_NAME_TOO_LONG, _("Setting `core.longPaths` may allow the deletion to succeed."));
1122+
}
11111123
errors++;
11121124
} else if (!quiet) {
11131125
qname = quote_path(item->string, NULL, &buf, 0);

0 commit comments

Comments
 (0)