Skip to content

Commit 74da98f

Browse files
pcloudsgitster
authored andcommitted
unpack-trees: mark new entries skip-worktree appropriately
Sparse checkout narrows worktree down based on the skip-worktree bit before and after $GIT_DIR/info/sparse-checkout application. If it does not have that bit before but does after, a narrow is detected and the file will be removed from worktree. New files added by merge, however, does not have skip-worktree bit. If those files appear to be outside checkout area, the same rule applies: the file gets removed from worktree even though they don't exist in worktree. Just pretend they have skip-worktree before in that case, so the rule is ignored. Signed-off-by: Nguyễn Thái Ngọc Duy <[email protected]> Reviewed-by: Jonathan Nieder <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 711f151 commit 74da98f

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

t/t1011-read-tree-sparse-checkout.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ test_expect_success 'read-tree adds to worktree, absent case' '
146146
test ! -f sub/added
147147
'
148148

149-
test_expect_failure 'read-tree adds to worktree, dirty case' '
149+
test_expect_success 'read-tree adds to worktree, dirty case' '
150150
echo init.t >.git/info/sparse-checkout &&
151151
git checkout -f removed &&
152152
mkdir sub &&

unpack-trees.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1096,6 +1096,8 @@ static int merged_entry(struct cache_entry *merge, struct cache_entry *old,
10961096
if (!old) {
10971097
if (verify_absent(merge, "overwritten", o))
10981098
return -1;
1099+
if (!o->skip_sparse_checkout && will_have_skip_worktree(merge, o))
1100+
update |= CE_SKIP_WORKTREE;
10991101
invalidate_ce_path(merge, o);
11001102
} else if (!(old->ce_flags & CE_CONFLICTED)) {
11011103
/*

0 commit comments

Comments
 (0)