Skip to content

Commit ace01dd

Browse files
Kevin Willforddscho
Kevin Willford
authored andcommitted
sparse-checkout: update files with a modify/delete conflict
When using the sparse-checkout feature, the file might not be on disk because the skip-worktree bit is on. Signed-off-by: Kevin Willford <[email protected]>
1 parent f3e6f6d commit ace01dd

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

merge-recursive.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1594,7 +1594,7 @@ static int handle_change_delete(struct merge_options *opt,
15941594
* path. We could call update_file_flags() with update_cache=0
15951595
* and update_wd=0, but that's a no-op.
15961596
*/
1597-
if (change_branch != opt->branch1 || alt_path)
1597+
if (change_branch != opt->branch1 || alt_path || !file_exists(update_path))
15981598
ret = update_file(opt, 0, changed, update_path);
15991599
}
16001600
free(alt_path);

t/meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -937,6 +937,7 @@ integration_tests = [
937937
't7612-merge-verify-signatures.sh',
938938
't7614-merge-signoff.sh',
939939
't7615-diff-algo-with-mergy-operations.sh',
940+
't7616-merge-sparse-checkout.sh',
940941
't7700-repack.sh',
941942
't7701-repack-unpack-unreachable.sh',
942943
't7702-repack-cyclic-alternate.sh',

t/t7616-merge-sparse-checkout.sh

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/bin/sh
2+
3+
test_description='merge can handle sparse-checkout'
4+
5+
. ./test-lib.sh
6+
7+
# merges with conflicts
8+
9+
test_expect_success 'setup' '
10+
git branch -M main &&
11+
test_commit a &&
12+
test_commit file &&
13+
git checkout -b delete-file &&
14+
git rm file.t &&
15+
test_tick &&
16+
git commit -m "remove file" &&
17+
git checkout main &&
18+
test_commit modify file.t changed
19+
'
20+
21+
test_expect_success 'merge conflict deleted file and modified' '
22+
echo "/a.t" >.git/info/sparse-checkout &&
23+
test_config core.sparsecheckout true &&
24+
git checkout -f &&
25+
test_path_is_missing file.t &&
26+
test_must_fail git merge delete-file &&
27+
test_path_is_file file.t &&
28+
test "changed" = "$(cat file.t)"
29+
'
30+
31+
test_done

0 commit comments

Comments
 (0)