Re: [PATCH 2/2] sparse-checkout: clear tracked sparse dirs
From: Elijah Newren <hidden>
Date: 2021-08-02 16:17:33
On Mon, Aug 2, 2021 at 8:34 AM Derrick Stolee [off-list ref] wrote:
On 7/30/2021 9:52 AM, Elijah Newren wrote:quoted
On Thu, Jul 29, 2021 at 11:27 AM Derrick Stolee via GitGitGadget [off-list ref] wrote:
...
quoted
quoted
+ */ + if (S_ISSPARSEDIR(ce->ce_mode) && + repo_file_exists(r, ce->name)) { + strbuf_setlen(&path, pathlen); + strbuf_addstr(&path, ce->name); + + /* + * Removal is "best effort". If something blocks + * the deletion, then continue with a warning. + */ + if (remove_dir_recursively(&path, 0)) + warning(_("failed to remove directory '%s'"), path.buf);Um, doesn't this delete untracked files that are not ignored as well as the ignored files? If so, was that intentional? I'm fully on board with removing the gitignore'd files, but I'm worried removing other untracked files is dangerous.I believe that 'git sparse-checkout (set|add|reapply)' will fail before reaching this method if there are untracked files that could potentially be removed. I will double-check to ensure this is the case. It is definitely my intention to protect any untracked, non-ignored files in these directories by failing the sparse-checkout modification.quoted
My implementation of this concept (in an external tool) was more along the lines of * Get $LIST_OF_NON_SPARSE_DIRECTORIES by walking `git ls-files -t` output and finding common fully-sparse directories * git clean -fX $LIST_OF_NON_SPARSE_DIRECTORIESI initially was running 'git clean -dfx -- <dir> ...' but that also requires parsing and expanding the index (or being very careful with the sparse index).
`git clean -dfx -- <dir> ...` could also be very dangerous because it'd delete untracked non-ignored files. You want -X rather than -x. One of those cases where capitalization is critical.