Skip to content

Commit 63b60b3

Browse files
derrickstoleegitster
authored andcommitted
add: update --chmod to skip sparse paths
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 0299a69 commit 63b60b3

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

builtin/add.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ static int chmod_pathspec(struct pathspec *pathspec, char flip, int show_only)
4747
struct cache_entry *ce = active_cache[i];
4848
int err;
4949

50-
if (!include_sparse && ce_skip_worktree(ce))
50+
if (!include_sparse &&
51+
(ce_skip_worktree(ce) ||
52+
!path_in_sparse_checkout(ce->name, &the_index)))
5153
continue;
5254

5355
if (pathspec && !ce_path_match(&the_index, ce, pathspec, NULL))

t/t3705-add-sparse-checkout.sh

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,11 +169,19 @@ test_expect_success 'git add fails outside of sparse-checkout definition' '
169169
test_must_fail git add sparse_entry &&
170170
test_sparse_entry_unstaged &&
171171
172+
test_must_fail git add --chmod=+x sparse_entry &&
173+
test_sparse_entry_unstaged &&
174+
172175
# Avoid munging CRLFs to avoid an error message
173176
git -c core.autocrlf=input add --sparse sparse_entry 2>stderr &&
174177
test_must_be_empty stderr &&
175178
test-tool read-cache --table >actual &&
176-
grep "^100644 blob.*sparse_entry\$" actual
179+
grep "^100644 blob.*sparse_entry\$" actual &&
180+
181+
git add --sparse --chmod=+x sparse_entry 2>stderr &&
182+
test_must_be_empty stderr &&
183+
test-tool read-cache --table >actual &&
184+
grep "^100755 blob.*sparse_entry\$" actual
177185
'
178186

179187
test_expect_success 'add obeys advice.updateSparsePath' '

0 commit comments

Comments
 (0)