Merge branch 'jc/maint-clean-nested-worktree-in-subdir' into maint
"git clean -d -f" (not "-d -f -f") is supposed to protect nested
working trees of independent git repositories that exist in the
current project working tree from getting removed, but the protection
applied only to such working trees that are at the top-level of the
current project by mistake.
* jc/maint-clean-nested-worktree-in-subdir:
clean: preserve nested git worktree in subdirectories
/* Do not descend and nuke a nested git work tree. */
if (kept_up)
*kept_up = 1;
return 0;
}
flag &= ~(REMOVE_DIR_KEEP_TOPLEVEL|REMOVE_DIR_KEEP_NESTED_GIT);
flag &= ~REMOVE_DIR_KEEP_TOPLEVEL;
dir = opendir(path->buf);
if (!dir) {
/* an empty dir could be removed even if it is unreadble */
if (!keep_toplevel)
return rmdir(path->buf);
else
@ -1208,7 +1212,7 @@ int remove_dir_recursively(struct strbuf *path, int flag)
@@ -1208,7 +1212,7 @@ int remove_dir_recursively(struct strbuf *path, int flag)
if (lstat(path->buf, &st))
; /* fall thru */
else if (S_ISDIR(st.st_mode)) {
if (!remove_dir_recursively(path, flag))
if (!remove_dir_recurse(path, flag, &kept_down))
continue; /* happy */
} else if (!only_empty && !unlink(path->buf))
continue; /* happy, too */
@ -1220,11 +1224,22 @@ int remove_dir_recursively(struct strbuf *path, int flag)
@@ -1220,11 +1224,22 @@ int remove_dir_recursively(struct strbuf *path, int flag)
closedir(dir);
strbuf_setlen(path, original_len);
if (!ret && !keep_toplevel)
if (!ret && !keep_toplevel && !kept_down)
ret = rmdir(path->buf);
else if (kept_up)
/*
* report the uplevel that it is not an error that we
* did not rmdir() our directory.
*/
*kept_up = !ret;
return ret;
}
int remove_dir_recursively(struct strbuf *path, int flag)