Skip to content

Commit 61d450f

Browse files
derrickstoleegitster
authored andcommitted
add: update --renormalize to skip sparse paths
We added checks for path_in_sparse_checkout() to portions of 'git add' that add warnings and prevent stagins a modification, but we skipped the --renormalize mode. Update renormalize_tracked_files() 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 63b60b3 commit 61d450f

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

builtin/add.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,9 @@ static int renormalize_tracked_files(const struct pathspec *pathspec, int flags)
154154
for (i = 0; i < active_nr; i++) {
155155
struct cache_entry *ce = active_cache[i];
156156

157-
if (ce_skip_worktree(ce))
157+
if (!include_sparse &&
158+
(ce_skip_worktree(ce) ||
159+
!path_in_sparse_checkout(ce->name, &the_index)))
158160
continue;
159161
if (ce_stage(ce))
160162
continue; /* do not touch unmerged paths */

t/t3705-add-sparse-checkout.sh

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,9 @@ test_expect_success 'git add fails outside of sparse-checkout definition' '
172172
test_must_fail git add --chmod=+x sparse_entry &&
173173
test_sparse_entry_unstaged &&
174174
175+
test_must_fail git add --renormalize sparse_entry &&
176+
test_sparse_entry_unstaged &&
177+
175178
# Avoid munging CRLFs to avoid an error message
176179
git -c core.autocrlf=input add --sparse sparse_entry 2>stderr &&
177180
test_must_be_empty stderr &&
@@ -181,7 +184,14 @@ test_expect_success 'git add fails outside of sparse-checkout definition' '
181184
git add --sparse --chmod=+x sparse_entry 2>stderr &&
182185
test_must_be_empty stderr &&
183186
test-tool read-cache --table >actual &&
184-
grep "^100755 blob.*sparse_entry\$" actual
187+
grep "^100755 blob.*sparse_entry\$" actual &&
188+
189+
git reset &&
190+
191+
# This will print a message over stderr on Windows.
192+
git add --sparse --renormalize sparse_entry &&
193+
git status --porcelain >actual &&
194+
grep "^M sparse_entry\$" actual
185195
'
186196

187197
test_expect_success 'add obeys advice.updateSparsePath' '

0 commit comments

Comments
 (0)