Thread (101 messages) flat view 101 messages, 9 authors, 2021-11-02

Re: [PATCH 09/13] rm: add --sparse option

From: Matheus Tavares Bernardino <hidden>
Date: 2021-08-27 21:18:02

On Tue, Aug 24, 2021 at 6:54 PM Derrick Stolee via GitGitGadget
[off-list ref] 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.)
quoted hunk ↗ jump to hunk
--- 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 ...
quoted hunk ↗ jump to hunk
                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.
quoted hunk ↗ jump to hunk
                        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!
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help