Skip to content

Commit a36b695

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 5ff1ebe commit a36b695

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
@@ -64,6 +64,9 @@ all advice messages.
6464
set their identity configuration.
6565
mergeConflict::
6666
Shown when various commands stop because of conflicts.
67+
nameTooLong::
68+
Advice shown if a filepath operation is attempted where the
69+
path was too long.
6770
nestedTag::
6871
Shown when a user attempts to recursively tag a tag object.
6972
pushAlreadyExists::

advice.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ static struct {
5959
[ADVICE_IGNORED_HOOK] = { "ignoredHook" },
6060
[ADVICE_IMPLICIT_IDENTITY] = { "implicitIdentity" },
6161
[ADVICE_MERGE_CONFLICT] = { "mergeConflict" },
62+
[ADVICE_NAME_TOO_LONG] = { "nameTooLong" },
6263
[ADVICE_NESTED_TAG] = { "nestedTag" },
6364
[ADVICE_OBJECT_NAME_WARNING] = { "objectNameWarning" },
6465
[ADVICE_PUSH_ALREADY_EXISTS] = { "pushAlreadyExists" },

advice.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ enum advice_type {
2626
ADVICE_IGNORED_HOOK,
2727
ADVICE_IMPLICIT_IDENTITY,
2828
ADVICE_MERGE_CONFLICT,
29+
ADVICE_NAME_TOO_LONG,
2930
ADVICE_NESTED_TAG,
3031
ADVICE_OBJECT_NAME_WARNING,
3132
ADVICE_PUSH_ALREADY_EXISTS,

builtin/clean.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "pathspec.h"
2323
#include "help.h"
2424
#include "prompt.h"
25+
#include "advice.h"
2526

2627
static int require_force = -1; /* unset */
2728
static int interactive;
@@ -217,6 +218,9 @@ static int remove_dirs(struct strbuf *path, const char *prefix, int force_flag,
217218
quote_path(path->buf, prefix, &quoted, 0);
218219
errno = saved_errno;
219220
warning_errno(_(msg_warn_remove_failed), quoted.buf);
221+
if (saved_errno == ENAMETOOLONG) {
222+
advise_if_enabled(ADVICE_NAME_TOO_LONG, _("Setting `core.longPaths` may allow the deletion to succeed."));
223+
}
220224
*dir_gone = 0;
221225
}
222226
ret = res;
@@ -252,6 +256,9 @@ static int remove_dirs(struct strbuf *path, const char *prefix, int force_flag,
252256
quote_path(path->buf, prefix, &quoted, 0);
253257
errno = saved_errno;
254258
warning_errno(_(msg_warn_remove_failed), quoted.buf);
259+
if (saved_errno == ENAMETOOLONG) {
260+
advise_if_enabled(ADVICE_NAME_TOO_LONG, _("Setting `core.longPaths` may allow the deletion to succeed."));
261+
}
255262
*dir_gone = 0;
256263
ret = 1;
257264
}
@@ -295,6 +302,9 @@ static int remove_dirs(struct strbuf *path, const char *prefix, int force_flag,
295302
quote_path(path->buf, prefix, &quoted, 0);
296303
errno = saved_errno;
297304
warning_errno(_(msg_warn_remove_failed), quoted.buf);
305+
if (saved_errno == ENAMETOOLONG) {
306+
advise_if_enabled(ADVICE_NAME_TOO_LONG, _("Setting `core.longPaths` may allow the deletion to succeed."));
307+
}
298308
*dir_gone = 0;
299309
ret = 1;
300310
}
@@ -1107,6 +1117,9 @@ int cmd_clean(int argc,
11071117
qname = quote_path(item->string, NULL, &buf, 0);
11081118
errno = saved_errno;
11091119
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+
}
11101123
errors++;
11111124
} else if (!quiet) {
11121125
qname = quote_path(item->string, NULL, &buf, 0);

0 commit comments

Comments
 (0)