Message ID | 6c9c986ff43fe7f065c27e61468534007e70d2a7.1629842085.git.gitgitgadget@gmail.com (mailing list archive) |
---|---|
State | Superseded |
Headers | show |
Series | Sparse-checkout: modify 'git add', 'git rm', and 'git add' behavior | expand |
On Tue, Aug 24, 2021 at 6:54 PM Derrick Stolee via GitGitGadget <gitgitgadget@gmail.com> wrote: > > Subject: [PATCH 09/12] rm: add --sparse option Maybe mention in the commit message that, for now, rm's --sparse only affects entries with the skip_worktree bit set? (Which will be changed in the following patch.) > --- a/builtin/rm.c > +++ b/builtin/rm.c > @@ -298,7 +300,8 @@ int cmd_rm(int argc, const char **argv, const char *prefix) > ensure_full_index(&the_index); > for (i = 0; i < active_nr; i++) { > const struct cache_entry *ce = active_cache[i]; > - if (ce_skip_worktree(ce)) > + > + if (!include_sparse && ce_skip_worktree(ce)) > continue; OK, we no longer ignore the skip_worktree entry if --sparse is given ... > if (!ce_path_match(&the_index, ce, &pathspec, seen)) > continue; > @@ -322,7 +325,8 @@ int cmd_rm(int argc, const char **argv, const char *prefix) > seen_any = 1; > else if (ignore_unmatch) > continue; > - else if (matches_skip_worktree(&pathspec, i, &skip_worktree_seen)) > + else if (!include_sparse && > + matches_skip_worktree(&pathspec, i, &skip_worktree_seen)) > string_list_append(&only_match_skip_worktree, original); ... and we also don't need to look for matches here as we won't display the error/advice match. > else > die(_("pathspec '%s' did not match any files"), original); > diff --git a/t/t3602-rm-sparse-checkout.sh b/t/t3602-rm-sparse-checkout.sh > index e9e9a15c74c..a34b978bfd8 100755 > --- a/t/t3602-rm-sparse-checkout.sh > +++ b/t/t3602-rm-sparse-checkout.sh > @@ -36,13 +36,25 @@ done > > test_expect_success 'recursive rm does not remove sparse entries' ' > git reset --hard && > - git sparse-checkout set sub/dir && > + git sparse-checkout set sub/dir/ && Is this change necessary? > git rm -r sub && > git status --porcelain -uno >actual && > echo "D sub/dir/e" >expected && > test_cmp expected actual > ' > > +test_expect_success 'recursive rm --sparse removes sparse entries' ' > + git reset --hard && > + git sparse-checkout set "sub/dir" && > + git rm --sparse -r sub && > + git status --porcelain -uno >actual && > + cat >expected <<-\EOF && > + D sub/d > + D sub/dir/e > + EOF > + test_cmp expected actual > +' Nice!
On 8/27/2021 5:17 PM, Matheus Tavares Bernardino wrote: > On Tue, Aug 24, 2021 at 6:54 PM Derrick Stolee via GitGitGadget > <gitgitgadget@gmail.com> wrote: >> >> Subject: [PATCH 09/12] rm: add --sparse option > > Maybe mention in the commit message that, for now, rm's --sparse only > affects entries with the skip_worktree bit set? (Which will be changed > in the following patch.) I will expand with these details. >> test_expect_success 'recursive rm does not remove sparse entries' ' >> git reset --hard && >> - git sparse-checkout set sub/dir && >> + git sparse-checkout set sub/dir/ && > > Is this change necessary? No, it is not. Thanks. -Stolee
diff --git a/Documentation/git-rm.txt b/Documentation/git-rm.txt index 26e9b284704..81bc23f3cdb 100644 --- a/Documentation/git-rm.txt +++ b/Documentation/git-rm.txt @@ -72,6 +72,12 @@ For more details, see the 'pathspec' entry in linkgit:gitglossary[7]. --ignore-unmatch:: Exit with a zero status even if no files matched. +--sparse:: + Allow updating index entries outside of the sparse-checkout cone. + Normally, `git rm` refuses to update index entries whose paths do + not fit within the sparse-checkout cone. See + linkgit:git-sparse-checkout[1] for more. + -q:: --quiet:: `git rm` normally outputs one line (in the form of an `rm` command) diff --git a/builtin/rm.c b/builtin/rm.c index 8a24c715e02..4208f3f9a5f 100644 --- a/builtin/rm.c +++ b/builtin/rm.c @@ -237,6 +237,7 @@ static int check_local_mod(struct object_id *head, int index_only) static int show_only = 0, force = 0, index_only = 0, recursive = 0, quiet = 0; static int ignore_unmatch = 0, pathspec_file_nul; +static int include_sparse; static char *pathspec_from_file; static struct option builtin_rm_options[] = { @@ -247,6 +248,7 @@ static struct option builtin_rm_options[] = { OPT_BOOL('r', NULL, &recursive, N_("allow recursive removal")), OPT_BOOL( 0 , "ignore-unmatch", &ignore_unmatch, N_("exit with a zero status even if nothing matched")), + OPT_BOOL(0, "sparse", &include_sparse, N_("allow updating entries outside of the sparse-checkout cone")), OPT_PATHSPEC_FROM_FILE(&pathspec_from_file), OPT_PATHSPEC_FILE_NUL(&pathspec_file_nul), OPT_END(), @@ -298,7 +300,8 @@ int cmd_rm(int argc, const char **argv, const char *prefix) ensure_full_index(&the_index); for (i = 0; i < active_nr; i++) { const struct cache_entry *ce = active_cache[i]; - if (ce_skip_worktree(ce)) + + if (!include_sparse && ce_skip_worktree(ce)) continue; if (!ce_path_match(&the_index, ce, &pathspec, seen)) continue; @@ -322,7 +325,8 @@ int cmd_rm(int argc, const char **argv, const char *prefix) seen_any = 1; else if (ignore_unmatch) continue; - else if (matches_skip_worktree(&pathspec, i, &skip_worktree_seen)) + else if (!include_sparse && + matches_skip_worktree(&pathspec, i, &skip_worktree_seen)) string_list_append(&only_match_skip_worktree, original); else die(_("pathspec '%s' did not match any files"), original); diff --git a/t/t3602-rm-sparse-checkout.sh b/t/t3602-rm-sparse-checkout.sh index e9e9a15c74c..a34b978bfd8 100755 --- a/t/t3602-rm-sparse-checkout.sh +++ b/t/t3602-rm-sparse-checkout.sh @@ -36,13 +36,25 @@ done test_expect_success 'recursive rm does not remove sparse entries' ' git reset --hard && - git sparse-checkout set sub/dir && + git sparse-checkout set sub/dir/ && git rm -r sub && git status --porcelain -uno >actual && echo "D sub/dir/e" >expected && test_cmp expected actual ' +test_expect_success 'recursive rm --sparse removes sparse entries' ' + git reset --hard && + git sparse-checkout set "sub/dir" && + git rm --sparse -r sub && + git status --porcelain -uno >actual && + cat >expected <<-\EOF && + D sub/d + D sub/dir/e + EOF + test_cmp expected actual +' + test_expect_success 'rm obeys advice.updateSparsePath' ' git reset --hard && git sparse-checkout set a &&