Merge branch 'da/mergetool-custom'
authorJunio C Hamano <gitster@pobox.com>
Mon, 1 Oct 2012 19:58:57 +0000 (12:58 -0700)
committerJunio C Hamano <gitster@pobox.com>
Mon, 1 Oct 2012 19:58:57 +0000 (12:58 -0700)
The actual external command to run for mergetool backend can be
specified with difftool/mergetool.$name.cmd configuration
variables, but this mechanism was ignored for the backends we
natively support.

* da/mergetool-custom:
mergetool--lib: Allow custom commands to override built-ins

1  2 
git-mergetool--lib.sh
t/t7610-mergetool.sh
diff --combined git-mergetool--lib.sh
index 54cb708254d38062983373c536589add648ae304,6988f9c0c0492b2a623c62420509ef64654c0f1b..f013a0350665e8c11b52853b5794631dcf7694d0
@@@ -104,13 -104,49 +104,49 @@@ run_merge_tool () 
  
        if merge_mode
        then
-               merge_cmd "$1"
+               run_merge_cmd "$1"
        else
-               diff_cmd "$1"
+               run_diff_cmd "$1"
        fi
        return $status
  }
  
+ # Run a either a configured or built-in diff tool
+ run_diff_cmd () {
+       merge_tool_cmd="$(get_merge_tool_cmd "$1")"
+       if test -n "$merge_tool_cmd"
+       then
+               ( eval $merge_tool_cmd )
+               status=$?
+               return $status
+       else
+               diff_cmd "$1"
+       fi
+ }
+ # Run a either a configured or built-in merge tool
+ run_merge_cmd () {
+       merge_tool_cmd="$(get_merge_tool_cmd "$1")"
+       if test -n "$merge_tool_cmd"
+       then
+               trust_exit_code="$(git config --bool \
+                       mergetool."$1".trustExitCode || echo false)"
+               if test "$trust_exit_code" = "false"
+               then
+                       touch "$BACKUP"
+                       ( eval $merge_tool_cmd )
+                       status=$?
+                       check_unchanged
+               else
+                       ( eval $merge_tool_cmd )
+                       status=$?
+               fi
+               return $status
+       else
+               merge_cmd "$1"
+       fi
+ }
  list_merge_tool_candidates () {
        if merge_mode
        then
                else
                        tools="opendiff kdiff3 tkdiff xxdiff meld $tools"
                fi
 -              tools="$tools gvimdiff diffuse ecmerge p4merge araxis bc3"
 +              tools="$tools gvimdiff diffuse ecmerge p4merge araxis bc3 codecompare"
        fi
        case "${VISUAL:-$EDITOR}" in
        *vim*)
diff --combined t/t7610-mergetool.sh
index 6fa0c70506b4a4f6b066d6f3d25aa0e499b419b5,0348ed2fb745a999377aab564e96c6cd1ebde62a..bc38737b2a5ebd9b7ba20fcb92ac87c48b9496c8
@@@ -55,16 -55,6 +55,16 @@@ test_expect_success 'setup' 
      git rm file12 &&
      git commit -m "branch1 changes" &&
  
 +    git checkout -b stash1 master &&
 +    echo stash1 change file11 >file11 &&
 +    git add file11 &&
 +    git commit -m "stash1 changes" &&
 +
 +    git checkout -b stash2 master &&
 +    echo stash2 change file11 >file11 &&
 +    git add file11 &&
 +    git commit -m "stash2 changes" &&
 +
      git checkout master &&
      git submodule update -N &&
      echo master updated >file1 &&
@@@ -203,35 -193,7 +203,35 @@@ test_expect_success 'mergetool skips re
      git reset --hard
  '
  
 +test_expect_success 'conflicted stash sets up rerere'  '
 +    git config rerere.enabled true &&
 +    git checkout stash1 &&
 +    echo "Conflicting stash content" >file11 &&
 +    git stash &&
 +
 +    git checkout --detach stash2 &&
 +    test_must_fail git stash apply &&
 +
 +    test -n "$(git ls-files -u)" &&
 +    conflicts="$(git rerere remaining)" &&
 +    test "$conflicts" = "file11" &&
 +    output="$(git mergetool --no-prompt)" &&
 +    test "$output" != "No files need merging" &&
 +
 +    git commit -am "save the stash resolution" &&
 +
 +    git reset --hard stash2 &&
 +    test_must_fail git stash apply &&
 +
 +    test -n "$(git ls-files -u)" &&
 +    conflicts="$(git rerere remaining)" &&
 +    test -z "$conflicts" &&
 +    output="$(git mergetool --no-prompt)" &&
 +    test "$output" = "No files need merging"
 +'
 +
  test_expect_success 'mergetool takes partial path' '
 +    git reset --hard
      git config rerere.enabled false &&
      git checkout -b test12 branch1 &&
      git submodule update -N &&
@@@ -509,4 -471,17 +509,17 @@@ test_expect_success 'file with no base
      git reset --hard master >/dev/null 2>&1
  '
  
+ test_expect_success 'custom commands override built-ins' '
+     git checkout -b test14 branch1 &&
+     git config mergetool.defaults.cmd "cat \"\$REMOTE\" >\"\$MERGED\"" &&
+     git config mergetool.defaults.trustExitCode true &&
+     test_must_fail git merge master &&
+     git mergetool --no-prompt --tool defaults -- both &&
+     echo master both added >expected &&
+     test_cmp both expected &&
+     git config --unset mergetool.defaults.cmd &&
+     git config --unset mergetool.defaults.trustExitCode &&
+     git reset --hard master >/dev/null 2>&1
+ '
  test_done