Skip to content

Commit cf790a8

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 343cdd4 commit cf790a8

File tree

4 files changed

+18
-0
lines changed

4 files changed

+18
-0
lines changed

Documentation/config/advice.txt

Lines changed: 3 additions & 0 deletions
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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ static struct {
5151
[ADVICE_GRAFT_FILE_DEPRECATED] = { "graftFileDeprecated", 1 },
5252
[ADVICE_IGNORED_HOOK] = { "ignoredHook", 1 },
5353
[ADVICE_IMPLICIT_IDENTITY] = { "implicitIdentity", 1 },
54+
[ADVICE_NAME_TOO_LONG] = { "nameTooLong", 1 },
5455
[ADVICE_NESTED_TAG] = { "nestedTag", 1 },
5556
[ADVICE_OBJECT_NAME_WARNING] = { "objectNameWarning", 1 },
5657
[ADVICE_PUSH_ALREADY_EXISTS] = { "pushAlreadyExists", 1 },

advice.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ struct string_list;
2525
ADVICE_GRAFT_FILE_DEPRECATED,
2626
ADVICE_IGNORED_HOOK,
2727
ADVICE_IMPLICIT_IDENTITY,
28+
ADVICE_NAME_TOO_LONG,
2829
ADVICE_NESTED_TAG,
2930
ADVICE_OBJECT_NAME_WARNING,
3031
ADVICE_PUSH_ALREADY_EXISTS,

builtin/clean.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "pathspec.h"
2424
#include "help.h"
2525
#include "prompt.h"
26+
#include "advice.h"
2627

2728
static int force = -1; /* unset */
2829
static int interactive;
@@ -215,6 +216,9 @@ static int remove_dirs(struct strbuf *path, const char *prefix, int force_flag,
215216
quote_path(path->buf, prefix, &quoted, 0);
216217
errno = saved_errno;
217218
warning_errno(_(msg_warn_remove_failed), quoted.buf);
219+
if (saved_errno == ENAMETOOLONG) {
220+
advise_if_enabled(ADVICE_NAME_TOO_LONG, _("Setting `core.longPaths` may allow the deletion to succeed."));
221+
}
218222
*dir_gone = 0;
219223
}
220224
ret = res;
@@ -250,6 +254,9 @@ static int remove_dirs(struct strbuf *path, const char *prefix, int force_flag,
250254
quote_path(path->buf, prefix, &quoted, 0);
251255
errno = saved_errno;
252256
warning_errno(_(msg_warn_remove_failed), quoted.buf);
257+
if (saved_errno == ENAMETOOLONG) {
258+
advise_if_enabled(ADVICE_NAME_TOO_LONG, _("Setting `core.longPaths` may allow the deletion to succeed."));
259+
}
253260
*dir_gone = 0;
254261
ret = 1;
255262
}
@@ -293,6 +300,9 @@ static int remove_dirs(struct strbuf *path, const char *prefix, int force_flag,
293300
quote_path(path->buf, prefix, &quoted, 0);
294301
errno = saved_errno;
295302
warning_errno(_(msg_warn_remove_failed), quoted.buf);
303+
if (saved_errno == ENAMETOOLONG) {
304+
advise_if_enabled(ADVICE_NAME_TOO_LONG, _("Setting `core.longPaths` may allow the deletion to succeed."));
305+
}
296306
*dir_gone = 0;
297307
ret = 1;
298308
}
@@ -1112,6 +1122,9 @@ int cmd_clean(int argc, const char **argv, const char *prefix)
11121122
qname = quote_path(item->string, NULL, &buf, 0);
11131123
errno = saved_errno;
11141124
warning_errno(_(msg_warn_remove_failed), qname);
1125+
if (saved_errno == ENAMETOOLONG) {
1126+
advise_if_enabled(ADVICE_NAME_TOO_LONG, _("Setting `core.longPaths` may allow the deletion to succeed."));
1127+
}
11151128
errors++;
11161129
} else if (!quiet) {
11171130
qname = quote_path(item->string, NULL, &buf, 0);

0 commit comments

Comments
 (0)