Skip to content

Commit 88546d3

Browse files
committed
Merge branch 'en/abort-df-conflict-fixes' into pu
* en/abort-df-conflict-fixes: read-cache: fix directory/file conflict handling in read_index_unmerged() t1015: demonstrate directory/file conflict recovery failures
2 parents df640d9 + e105e8b commit 88546d3

4 files changed

+131
-9
lines changed

read-cache.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2808,10 +2808,13 @@ int write_locked_index(struct index_state *istate, struct lock_file *lock,
28082808

28092809
/*
28102810
* Read the index file that is potentially unmerged into given
2811-
* index_state, dropping any unmerged entries. Returns true if
2812-
* the index is unmerged. Callers who want to refuse to work
2813-
* from an unmerged state can call this and check its return value,
2814-
* instead of calling read_cache().
2811+
* index_state, dropping any unmerged entries to stage #0 (potentially
2812+
* resulting in a path appearing as both a file and a directory in the
2813+
* index; the caller is responsible to clear out the extra entries
2814+
* before writing the index to a tree). Returns true if the index is
2815+
* unmerged. Callers who want to refuse to work from an unmerged
2816+
* state can call this and check its return value, instead of calling
2817+
* read_cache().
28152818
*/
28162819
int read_index_unmerged(struct index_state *istate)
28172820
{
@@ -2833,7 +2836,7 @@ int read_index_unmerged(struct index_state *istate)
28332836
new_ce->ce_flags = create_ce_flags(0) | CE_CONFLICTED;
28342837
new_ce->ce_namelen = len;
28352838
new_ce->ce_mode = ce->ce_mode;
2836-
if (add_index_entry(istate, new_ce, 0))
2839+
if (add_index_entry(istate, new_ce, ADD_CACHE_SKIP_DFCHECK))
28372840
return error("%s: cannot drop to stage #0",
28382841
new_ce->name);
28392842
}

t/t1015-read-index-unmerged.sh

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
#!/bin/sh
2+
3+
test_description='Test various callers of read_index_unmerged'
4+
. ./test-lib.sh
5+
6+
test_expect_success 'setup modify/delete + directory/file conflict' '
7+
test_create_repo df_plus_modify_delete &&
8+
(
9+
cd df_plus_modify_delete &&
10+
11+
test_write_lines a b c d e f g h >letters &&
12+
git add letters &&
13+
git commit -m initial &&
14+
15+
git checkout -b modify &&
16+
# Throw in letters.txt for sorting order fun
17+
# ("letters.txt" sorts between "letters" and "letters/file")
18+
echo i >>letters &&
19+
echo "version 2" >letters.txt &&
20+
git add letters letters.txt &&
21+
git commit -m modified &&
22+
23+
git checkout -b delete HEAD^ &&
24+
git rm letters &&
25+
mkdir letters &&
26+
>letters/file &&
27+
echo "version 1" >letters.txt &&
28+
git add letters letters.txt &&
29+
git commit -m deleted
30+
)
31+
'
32+
33+
test_expect_success 'read-tree --reset cleans unmerged entries' '
34+
test_when_finished "git -C df_plus_modify_delete clean -f" &&
35+
test_when_finished "git -C df_plus_modify_delete reset --hard" &&
36+
(
37+
cd df_plus_modify_delete &&
38+
39+
git checkout delete^0 &&
40+
test_must_fail git merge modify &&
41+
42+
git read-tree --reset HEAD &&
43+
git ls-files -u >conflicts &&
44+
test_must_be_empty conflicts
45+
)
46+
'
47+
48+
test_expect_success 'One reset --hard cleans unmerged entries' '
49+
test_when_finished "git -C df_plus_modify_delete clean -f" &&
50+
test_when_finished "git -C df_plus_modify_delete reset --hard" &&
51+
(
52+
cd df_plus_modify_delete &&
53+
54+
git checkout delete^0 &&
55+
test_must_fail git merge modify &&
56+
57+
git reset --hard &&
58+
test_path_is_missing .git/MERGE_HEAD &&
59+
git ls-files -u >conflicts &&
60+
test_must_be_empty conflicts
61+
)
62+
'
63+
64+
test_expect_success 'setup directory/file conflict + simple edit/edit' '
65+
test_create_repo df_plus_edit_edit &&
66+
(
67+
cd df_plus_edit_edit &&
68+
69+
test_seq 1 10 >numbers &&
70+
git add numbers &&
71+
git commit -m initial &&
72+
73+
git checkout -b d-edit &&
74+
mkdir foo &&
75+
echo content >foo/bar &&
76+
git add foo &&
77+
echo 11 >>numbers &&
78+
git add numbers &&
79+
git commit -m "directory and edit" &&
80+
81+
git checkout -b f-edit d-edit^1 &&
82+
echo content >foo &&
83+
git add foo &&
84+
echo eleven >>numbers &&
85+
git add numbers &&
86+
git commit -m "file and edit"
87+
)
88+
'
89+
90+
test_expect_success 'git merge --abort succeeds despite D/F conflict' '
91+
test_when_finished "git -C df_plus_edit_edit clean -f" &&
92+
test_when_finished "git -C df_plus_edit_edit reset --hard" &&
93+
(
94+
cd df_plus_edit_edit &&
95+
96+
git checkout f-edit^0 &&
97+
test_must_fail git merge d-edit^0 &&
98+
99+
git merge --abort &&
100+
test_path_is_missing .git/MERGE_HEAD &&
101+
git ls-files -u >conflicts &&
102+
test_must_be_empty conflicts
103+
)
104+
'
105+
106+
test_expect_success 'git am --skip succeeds despite D/F conflict' '
107+
test_when_finished "git -C df_plus_edit_edit clean -f" &&
108+
test_when_finished "git -C df_plus_edit_edit reset --hard" &&
109+
(
110+
cd df_plus_edit_edit &&
111+
112+
git checkout f-edit^0 &&
113+
git format-patch -1 d-edit &&
114+
test_must_fail git am -3 0001*.patch &&
115+
116+
git am --skip &&
117+
test_path_is_missing .git/rebase-apply &&
118+
git ls-files -u >conflicts &&
119+
test_must_be_empty conflicts
120+
)
121+
'
122+
123+
test_done

t/t6020-merge-df.sh

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,6 @@ test_expect_success 'modify/delete + directory/file conflict' '
8989
'
9090

9191
test_expect_success 'modify/delete + directory/file conflict; other way' '
92-
# Yes, we really need the double reset since "letters" appears as
93-
# both a file and a directory.
94-
git reset --hard &&
9592
git reset --hard &&
9693
git clean -f &&
9794
git checkout modify^0 &&

t/t6042-merge-rename-corner-cases.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,6 @@ test_expect_success 'rename/directory conflict + content merge conflict' '
323323
(
324324
cd rename-directory-1 &&
325325
326-
git reset --hard &&
327326
git reset --hard &&
328327
git clean -fdqx &&
329328

0 commit comments

Comments
 (0)