]> git.ipfire.org Git - thirdparty/git.git/commitdiff
add: update --chmod to skip sparse paths
authorDerrick Stolee <dstolee@microsoft.com>
Fri, 24 Sep 2021 15:39:09 +0000 (15:39 +0000)
committerJunio C Hamano <gitster@pobox.com>
Tue, 28 Sep 2021 17:31:02 +0000 (10:31 -0700)
We added checks for path_in_sparse_checkout() to portions of 'git add'
that add warnings and prevent staging a modification, but we skipped the
--chmod mode. Update chmod_pathspec() to ignore cache entries whose path
is outside of the sparse-checkout cone (unless --sparse is provided).
Add a test in t3705.

Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/add.c
t/t3705-add-sparse-checkout.sh

index f8e3930608dcb2cb6ca6eba03f333a40a6f482ef..f87b8134b6746c5dc9458a4da6aa69a1f429b69e 100644 (file)
@@ -47,7 +47,9 @@ static int chmod_pathspec(struct pathspec *pathspec, char flip, int show_only)
                struct cache_entry *ce = active_cache[i];
                int err;
 
-               if (!include_sparse && ce_skip_worktree(ce))
+               if (!include_sparse &&
+                   (ce_skip_worktree(ce) ||
+                    !path_in_sparse_checkout(ce->name, &the_index)))
                        continue;
 
                if (pathspec && !ce_path_match(&the_index, ce, pathspec, NULL))
index 3cab82092d4facac117bede72f3ada88f930ffa3..0ae674a17a926d3354b50fa216b1330c95c00a7f 100755 (executable)
@@ -169,11 +169,19 @@ test_expect_success 'git add fails outside of sparse-checkout definition' '
        test_must_fail git add sparse_entry &&
        test_sparse_entry_unstaged &&
 
+       test_must_fail git add --chmod=+x sparse_entry &&
+       test_sparse_entry_unstaged &&
+
        # Avoid munging CRLFs to avoid an error message
        git -c core.autocrlf=input add --sparse sparse_entry 2>stderr &&
        test_must_be_empty stderr &&
        test-tool read-cache --table >actual &&
-       grep "^100644 blob.*sparse_entry\$" actual
+       grep "^100644 blob.*sparse_entry\$" actual &&
+
+       git add --sparse --chmod=+x sparse_entry 2>stderr &&
+       test_must_be_empty stderr &&
+       test-tool read-cache --table >actual &&
+       grep "^100755 blob.*sparse_entry\$" actual
 '
 
 test_expect_success 'add obeys advice.updateSparsePath' '