@matheusbsbs / matheus-bagliano / commits / bb0a484e98
Fork 0

mergetool: Skip autoresolved paths

When mergetool is run without path limiters it loops over each entry in 'git ls-files -u'. This includes autoresolved paths. Teach mergetool to only merge files listed in 'rerere status' when rerere is enabled. There are some subtle but harmless changes in behavior. We now call cd_to_toplevel when no paths are given. We do this because 'rerere status' paths are always relative to the root. This is beneficial for the non-rerere use as well in that mergetool now runs against all unmerged files regardless of the current directory. This also slightly tweaks the output when run without paths to be more readable. The old output: Merging the files: foo bar baz The new output: Merging: foo bar baz Signed-off-by: David Aguilar <davvid@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

David Aguilar committed Aug 17, 2010 at 02:22 UTC bb0a484e985ef8d9bbbbeb172b1fcf4982634bef
2 files changed +57 -17
git-mergetool.sh
+23 -5
@@ -264,17 +264,35 @@ merge_keep_temporaries="$(git config --bool mergetool.keepTemporaries || echo fa
264
265 last_status=0
266 rollup_status=0
267 +rerere=false
268 +
269 +files_to_merge() {
270 + if test "$rerere" = true
271 + then
272 + git rerere status
273 + else
274 + git ls-files -u | sed -e 's/^[^ ]* //' | sort -u
275 + fi
276 +}
277 +
278
279 if test $# -eq 0 ; then
269 - files=$(git ls-files -u | sed -e 's/^[^ ]* //' | sort -u)
280 + cd_to_toplevel
281 +
282 + if test -e "$GIT_DIR/MERGE_RR"
283 + then
284 + rerere=true
285 + fi
286 +
287 + files=$(files_to_merge)
288 if test -z "$files" ; then
289 echo "No files need merging"
290 exit 0
291 fi
274 - echo Merging the files: "$files"
275 - git ls-files -u |
276 - sed -e 's/^[^ ]* //' |
277 - sort -u |
292 + printf "Merging:\n"
293 + printf "$files\n"
294 +
295 + files_to_merge |
296 while IFS= read i
297 do
298 if test $last_status -ne 0; then
t/t7610-mergetool.sh
+34 -12
@@ -14,6 +14,7 @@ Testing basic merge tool invocation'
14 # running mergetool
15
16 test_expect_success 'setup' '
17 + git config rerere.enabled true &&
18 echo master >file1 &&
19 mkdir subdir &&
20 echo master sub >subdir/file3 &&
@@ -71,19 +72,40 @@ test_expect_success 'mergetool in subdir' '
72 cd subdir && (
73 test_must_fail git merge master >/dev/null 2>&1 &&
74 ( yes "" | git mergetool file3 >/dev/null 2>&1 ) &&
74 - test "$(cat file3)" = "master new sub" )
75 + test "$(cat file3)" = "master new sub") &&
76 + cd ..
77 '
78
77 -# We can't merge files from parent directories when running mergetool
78 -# from a subdir. Is this a bug?
79 -#
80 -#test_expect_failure 'mergetool in subdir' '
81 -# cd subdir && (
82 -# ( yes "" | git mergetool ../file1 >/dev/null 2>&1 ) &&
83 -# ( yes "" | git mergetool ../file2 >/dev/null 2>&1 ) &&
84 -# test "$(cat ../file1)" = "master updated" &&
85 -# test "$(cat ../file2)" = "master new" &&
86 -# git commit -m "branch1 resolved with mergetool - subdir" )
87 -#'
79 +test_expect_success 'mergetool on file in parent dir' '
80 + cd subdir && (
81 + ( yes "" | git mergetool ../file1 >/dev/null 2>&1 ) &&
82 + ( yes "" | git mergetool ../file2 >/dev/null 2>&1 ) &&
83 + test "$(cat ../file1)" = "master updated" &&
84 + test "$(cat ../file2)" = "master new" &&
85 + git commit -m "branch1 resolved with mergetool - subdir") &&
86 + cd ..
87 +'
88 +
89 +test_expect_success 'mergetool skips autoresolved' '
90 + git checkout -b test4 branch1 &&
91 + test_must_fail git merge master &&
92 + test -n "$(git ls-files -u)" &&
93 + output="$(git mergetool --no-prompt)" &&
94 + test "$output" = "No files need merging" &&
95 + git reset --hard
96 +'
97 +
98 +test_expect_success 'mergetool merges all from subdir' '
99 + cd subdir && (
100 + git config rerere.enabled false &&
101 + test_must_fail git merge master &&
102 + git mergetool --no-prompt &&
103 + test "$(cat ../file1)" = "master updated" &&
104 + test "$(cat ../file2)" = "master new" &&
105 + test "$(cat file3)" = "master new sub" &&
106 + git add ../file1 ../file2 file3 &&
107 + git commit -m "branch2 resolved by mergetool from subdir") &&
108 + cd ..
109 +'
110
111 test_done