Skip to content

Commit 2f59c94

Browse files
Martin von Zweigbergkgitster
authored andcommitted
mergetool: don't skip modify/remove conflicts
Since bb0a484 (mergetool: Skip autoresolved paths, 2010-08-17), mergetool uses different ways of figuring out the list of files with merge conflicts depending on whether rerere is active. If rerere is active, mergetool will use 'git rerere status' to list the files with remaining conflicts. However, the output from that command does not list conflicts of types that rerere does not handle, such as modify/remove conflicts. Another problem with solely relying on the output from 'git rerere status' is that, for new conflicts that are not yet known to rerere, the output from the command will list the files even after adding them to the index. This means that if the conflicts in some files have been resolved and 'git mergetool' is run again, it will ask the user something like the following for each of those files. file1: file does not need merging Continue merging other unresolved paths (y/n) ? Solve both of these problems by replacing the call to 'git rerere status' with a call to the new 'git rerere remaining' that was introduced in the previous commit. Signed-off-by: Martin von Zweigbergk <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ac49f5c commit 2f59c94

File tree

2 files changed

+35
-7
lines changed

2 files changed

+35
-7
lines changed

git-mergetool.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ rerere=false
269269
files_to_merge() {
270270
if test "$rerere" = true
271271
then
272-
git rerere status
272+
git rerere remaining
273273
else
274274
git ls-files -u | sed -e 's/^[^ ]* //' | sort -u
275275
fi

t/t7610-mergetool.sh

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,33 @@ Testing basic merge tool invocation'
1616
test_expect_success 'setup' '
1717
git config rerere.enabled true &&
1818
echo master >file1 &&
19+
echo master file11 >file11 &&
20+
echo master file12 >file12 &&
21+
echo master file13 >file13 &&
22+
echo master file14 >file14 &&
1923
mkdir subdir &&
2024
echo master sub >subdir/file3 &&
21-
git add file1 subdir/file3 &&
22-
git commit -m "added file1" &&
25+
git add file1 file1[1-4] subdir/file3 &&
26+
git commit -m "add initial versions" &&
2327
2428
git checkout -b branch1 master &&
2529
echo branch1 change >file1 &&
2630
echo branch1 newfile >file2 &&
31+
echo branch1 change file11 >file11 &&
32+
echo branch1 change file13 >file13 &&
2733
echo branch1 sub >subdir/file3 &&
28-
git add file1 file2 subdir/file3 &&
34+
git add file1 file11 file13 file2 subdir/file3 &&
35+
git rm file12 &&
2936
git commit -m "branch1 changes" &&
3037
3138
git checkout master &&
3239
echo master updated >file1 &&
3340
echo master new >file2 &&
41+
echo master updated file12 >file12 &&
42+
echo master updated file14 >file14 &&
3443
echo master new sub >subdir/file3 &&
35-
git add file1 file2 subdir/file3 &&
44+
git add file1 file12 file14 file2 subdir/file3 &&
45+
git rm file11 &&
3646
git commit -m "master updates" &&
3747
3848
git config merge.tool mytool &&
@@ -46,6 +56,8 @@ test_expect_success 'custom mergetool' '
4656
( yes "" | git mergetool file1 >/dev/null 2>&1 ) &&
4757
( yes "" | git mergetool file2 >/dev/null 2>&1 ) &&
4858
( yes "" | git mergetool subdir/file3 >/dev/null 2>&1 ) &&
59+
( yes "d" | git mergetool file11 >/dev/null 2>&1 ) &&
60+
( yes "d" | git mergetool file12 >/dev/null 2>&1 ) &&
4961
test "$(cat file1)" = "master updated" &&
5062
test "$(cat file2)" = "master new" &&
5163
test "$(cat subdir/file3)" = "master new sub" &&
@@ -59,6 +71,8 @@ test_expect_success 'mergetool crlf' '
5971
( yes "" | git mergetool file1 >/dev/null 2>&1 ) &&
6072
( yes "" | git mergetool file2 >/dev/null 2>&1 ) &&
6173
( yes "" | git mergetool subdir/file3 >/dev/null 2>&1 ) &&
74+
( yes "d" | git mergetool file11 >/dev/null 2>&1 ) &&
75+
( yes "d" | git mergetool file12 >/dev/null 2>&1 ) &&
6276
test "$(printf x | cat file1 -)" = "$(printf "master updated\r\nx")" &&
6377
test "$(printf x | cat file2 -)" = "$(printf "master new\r\nx")" &&
6478
test "$(printf x | cat subdir/file3 -)" = "$(printf "master new sub\r\nx")" &&
@@ -82,6 +96,8 @@ test_expect_success 'mergetool on file in parent dir' '
8296
cd subdir &&
8397
( yes "" | git mergetool ../file1 >/dev/null 2>&1 ) &&
8498
( yes "" | git mergetool ../file2 >/dev/null 2>&1 ) &&
99+
( yes "d" | git mergetool ../file11 >/dev/null 2>&1 ) &&
100+
( yes "d" | git mergetool ../file12 >/dev/null 2>&1 ) &&
85101
test "$(cat ../file1)" = "master updated" &&
86102
test "$(cat ../file2)" = "master new" &&
87103
git commit -m "branch1 resolved with mergetool - subdir"
@@ -92,6 +108,8 @@ test_expect_success 'mergetool skips autoresolved' '
92108
git checkout -b test4 branch1 &&
93109
test_must_fail git merge master &&
94110
test -n "$(git ls-files -u)" &&
111+
( yes "d" | git mergetool file11 >/dev/null 2>&1 ) &&
112+
( yes "d" | git mergetool file12 >/dev/null 2>&1 ) &&
95113
output="$(git mergetool --no-prompt)" &&
96114
test "$output" = "No files need merging" &&
97115
git reset --hard
@@ -102,13 +120,23 @@ test_expect_success 'mergetool merges all from subdir' '
102120
cd subdir &&
103121
git config rerere.enabled false &&
104122
test_must_fail git merge master &&
105-
git mergetool --no-prompt &&
123+
( yes "d" "d" | git mergetool --no-prompt ) &&
106124
test "$(cat ../file1)" = "master updated" &&
107125
test "$(cat ../file2)" = "master new" &&
108126
test "$(cat file3)" = "master new sub" &&
109-
git add ../file1 ../file2 file3 &&
110127
git commit -m "branch2 resolved by mergetool from subdir"
111128
)
112129
'
113130

131+
test_expect_success 'mergetool skips resolved paths when rerere is active' '
132+
git config rerere.enabled true &&
133+
rm -rf .git/rr-cache &&
134+
git checkout -b test5 branch1
135+
test_must_fail git merge master >/dev/null 2>&1 &&
136+
( yes "d" "d" | git mergetool --no-prompt >/dev/null 2>&1 ) &&
137+
output="$(yes "n" | git mergetool --no-prompt)" &&
138+
test "$output" = "No files need merging" &&
139+
git reset --hard
140+
'
141+
114142
test_done

0 commit comments

Comments
 (0)