2626#include "pathspec.h"
2727#include "help.h"
2828#include "prompt.h"
29+ #include "advice.h"
2930
3031static int require_force = -1 ; /* unset */
3132static 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 }
@@ -1042,6 +1052,7 @@ int cmd_clean(int argc,
10421052
10431053 if (repo_read_index (the_repository ) < 0 )
10441054 die (_ ("index file corrupt" ));
1055+ enable_fscache (the_repository -> index -> cache_nr );
10451056
10461057 pl = add_pattern_list (& dir , EXC_CMDL , "--exclude option" );
10471058 for (i = 0 ; i < exclude_list .nr ; i ++ )
@@ -1108,6 +1119,9 @@ int cmd_clean(int argc,
11081119 qname = quote_path (item -> string , NULL , & buf , 0 );
11091120 errno = saved_errno ;
11101121 warning_errno (_ (msg_warn_remove_failed ), qname );
1122+ if (saved_errno == ENAMETOOLONG ) {
1123+ advise_if_enabled (ADVICE_NAME_TOO_LONG , _ ("Setting `core.longPaths` may allow the deletion to succeed." ));
1124+ }
11111125 errors ++ ;
11121126 } else if (!quiet ) {
11131127 qname = quote_path (item -> string , NULL , & buf , 0 );
@@ -1116,6 +1130,7 @@ int cmd_clean(int argc,
11161130 }
11171131 }
11181132
1133+ disable_fscache ();
11191134 strbuf_release (& abs_path );
11201135 strbuf_release (& buf );
11211136 string_list_clear (& del_list , 0 );
0 commit comments