Skip to content

Commit a813d9e

Browse files
committed
Merge branch 'sl/worktree-sparse'
"git worktree" learned to work better with sparse index feature. * sl/worktree-sparse: worktree: integrate with sparse-index
2 parents dcedba1 + 8fac776 commit a813d9e

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

builtin/worktree.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1407,5 +1407,9 @@ int cmd_worktree(int ac, const char **av, const char *prefix)
14071407
prefix = "";
14081408

14091409
ac = parse_options(ac, av, prefix, options, git_worktree_usage, 0);
1410+
1411+
prepare_repo_settings(the_repository);
1412+
the_repository->settings.command_requires_full_index = 0;
1413+
14101414
return fn(ac, av, prefix);
14111415
}

t/perf/p2000-sparse-operations.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,5 +133,6 @@ test_perf_on_all git diff-files
133133
test_perf_on_all git diff-files -- $SPARSE_CONE/a
134134
test_perf_on_all git diff-tree HEAD
135135
test_perf_on_all git diff-tree HEAD -- $SPARSE_CONE/a
136+
test_perf_on_all "git worktree add ../temp && git worktree remove ../temp"
136137

137138
test_done

t/t1092-sparse-checkout-compatibility.sh

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2222,4 +2222,41 @@ test_expect_success 'sparse-index is not expanded: diff-tree' '
22222222
ensure_not_expanded diff-tree HEAD update-folder1 -- folder1/a
22232223
'
22242224

2225+
test_expect_success 'worktree' '
2226+
init_repos &&
2227+
2228+
write_script edit-contents <<-\EOF &&
2229+
echo text >>"$1"
2230+
EOF
2231+
2232+
for repo in full-checkout sparse-checkout sparse-index
2233+
do
2234+
worktree=${repo}-wt &&
2235+
git -C $repo worktree add ../$worktree &&
2236+
2237+
# Compare worktree content with "ls"
2238+
(cd $repo && ls) >worktree_contents &&
2239+
(cd $worktree && ls) >new_worktree_contents &&
2240+
test_cmp worktree_contents new_worktree_contents &&
2241+
2242+
# Compare index content with "ls-files --sparse"
2243+
git -C $repo ls-files --sparse >index_contents &&
2244+
git -C $worktree ls-files --sparse >new_index_contents &&
2245+
test_cmp index_contents new_index_contents &&
2246+
2247+
git -C $repo worktree remove ../$worktree || return 1
2248+
done &&
2249+
2250+
test_all_match git worktree add .worktrees/hotfix &&
2251+
run_on_all ../edit-contents .worktrees/hotfix/deep/a &&
2252+
test_all_match test_must_fail git worktree remove .worktrees/hotfix
2253+
'
2254+
2255+
test_expect_success 'worktree is not expanded' '
2256+
init_repos &&
2257+
2258+
ensure_not_expanded worktree add .worktrees/hotfix &&
2259+
ensure_not_expanded worktree remove .worktrees/hotfix
2260+
'
2261+
22252262
test_done

0 commit comments

Comments
 (0)