Skip to content

Commit e2b2c87

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 a07bc94 commit e2b2c87

File tree

4 files changed

+18
-0
lines changed

4 files changed

+18
-0
lines changed

Documentation/config/advice.adoc

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
@@ -61,6 +61,7 @@ static struct {
6161
[ADVICE_IGNORED_HOOK] = { "ignoredHook" },
6262
[ADVICE_IMPLICIT_IDENTITY] = { "implicitIdentity" },
6363
[ADVICE_MERGE_CONFLICT] = { "mergeConflict" },
64+
[ADVICE_NAME_TOO_LONG] = { "nameTooLong" },
6465
[ADVICE_NESTED_TAG] = { "nestedTag" },
6566
[ADVICE_OBJECT_NAME_WARNING] = { "objectNameWarning" },
6667
[ADVICE_PUSH_ALREADY_EXISTS] = { "pushAlreadyExists" },

advice.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ enum advice_type {
2828
ADVICE_IGNORED_HOOK,
2929
ADVICE_IMPLICIT_IDENTITY,
3030
ADVICE_MERGE_CONFLICT,
31+
ADVICE_NAME_TOO_LONG,
3132
ADVICE_NESTED_TAG,
3233
ADVICE_OBJECT_NAME_WARNING,
3334
ADVICE_PUSH_ALREADY_EXISTS,

builtin/clean.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "pathspec.h"
2727
#include "help.h"
2828
#include "prompt.h"
29+
#include "advice.h"
2930

3031
static int require_force = -1; /* unset */
3132
static int interactive;
@@ -221,6 +222,9 @@ static int remove_dirs(struct strbuf *path, const char *prefix, int force_flag,
221222
quote_path(path->buf, prefix, &quoted, 0);
222223
errno = saved_errno;
223224
warning_errno(_(msg_warn_remove_failed), quoted.buf);
225+
if (saved_errno == ENAMETOOLONG) {
226+
advise_if_enabled(ADVICE_NAME_TOO_LONG, _("Setting `core.longPaths` may allow the deletion to succeed."));
227+
}
224228
*dir_gone = 0;
225229
}
226230
ret = res;
@@ -256,6 +260,9 @@ static int remove_dirs(struct strbuf *path, const char *prefix, int force_flag,
256260
quote_path(path->buf, prefix, &quoted, 0);
257261
errno = saved_errno;
258262
warning_errno(_(msg_warn_remove_failed), quoted.buf);
263+
if (saved_errno == ENAMETOOLONG) {
264+
advise_if_enabled(ADVICE_NAME_TOO_LONG, _("Setting `core.longPaths` may allow the deletion to succeed."));
265+
}
259266
*dir_gone = 0;
260267
ret = 1;
261268
}
@@ -299,6 +306,9 @@ static int remove_dirs(struct strbuf *path, const char *prefix, int force_flag,
299306
quote_path(path->buf, prefix, &quoted, 0);
300307
errno = saved_errno;
301308
warning_errno(_(msg_warn_remove_failed), quoted.buf);
309+
if (saved_errno == ENAMETOOLONG) {
310+
advise_if_enabled(ADVICE_NAME_TOO_LONG, _("Setting `core.longPaths` may allow the deletion to succeed."));
311+
}
302312
*dir_gone = 0;
303313
ret = 1;
304314
}
@@ -1111,6 +1121,9 @@ int cmd_clean(int argc,
11111121
qname = quote_path(item->string, NULL, &buf, 0);
11121122
errno = saved_errno;
11131123
warning_errno(_(msg_warn_remove_failed), qname);
1124+
if (saved_errno == ENAMETOOLONG) {
1125+
advise_if_enabled(ADVICE_NAME_TOO_LONG, _("Setting `core.longPaths` may allow the deletion to succeed."));
1126+
}
11141127
errors++;
11151128
} else if (!quiet) {
11161129
qname = quote_path(item->string, NULL, &buf, 0);

0 commit comments

Comments
 (0)