Skip to content

Commit 32d43fc

Browse files
Kevin Willforddscho
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 <kewillf@microsoft.com>
1 parent 52c0241 commit 32d43fc

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

merge-recursive.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1546,7 +1546,7 @@ static int handle_change_delete(struct merge_options *opt,
15461546
* path. We could call update_file_flags() with update_cache=0
15471547
* and update_wd=0, but that's a no-op.
15481548
*/
1549-
if (change_branch != opt->branch1 || alt_path)
1549+
if (change_branch != opt->branch1 || alt_path || !file_exists(update_path))
15501550
ret = update_file(opt, 0, changed, update_path);
15511551
}
15521552
free(alt_path);

t/t7615-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)