Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cygwin Git: The merge tool kdiff3 is not available

Tags:

git

cygwin

kdiff3

I'm trying to get my cygwin git installation working with kdiff3.

I followed Noam Lewis' instructions here: http://noamlewis.wordpress.com/2011/03/22/how-to-use-kdiff3-as-a-difftool-mergetool-with-cygwin-git/

But it's not working :(

Running

 git mergetool -t kdiff3

Gives this result:

Normal merge conflict for ...
  {local}: modified file
  {remote}: modified file
Hit return to start merge resolution tool (kdiff3):
The merge tool kdiff3 is not available as '~/kdiff3.sh'

However, running

~/kdiff3.sh

Opens kdiff3 as expected.

Here's my .gitconfig:

[diff]
        tool = kdiff3
[merge]
        tool = kdiff3
[mergetool "kdiff3"]
        path = ~/kdiff3.sh
        keepBackup = false
        trustExitCode = false

kdiff3.sh

#!/bin/sh
RESULT=""
for arg
  do
    if [[ "" != "$arg" ]] && [[ -e $arg ]];
      then
        OUT=`cygpath -wa $arg`
      else
        OUT=$arg
      if [[ $arg == -* ]];
        then
          OUT=$arg
        else
          OUT="'$arg'"
      fi
    fi
    RESULT=$RESULT" "$OUT
  done
/cygdrive/c/Program\ Files\ \(x86\)/KDiff3/kdiff3.exe $RESULT
like image 823
Mike Hadlow Avatar asked Jan 31 '14 15:01

Mike Hadlow


People also ask

How do I configure Mergetool?

git mergetool is fully configurable so you can pretty much chose your favourite tool. In brief, you can set a default mergetool by setting the user config variable merge. tool . If the merge tool is one of the ones supported natively by it you just have to set mergetool.


2 Answers

The wrap shell script is not necessary. I'm using kdiff3 installed in windows and set its folder in path and git in cygwin. If you don't set path for kdiff3 you need to give the full path in cmd as cmd = /cygdrive/c/apps/KDiff3/kdiff3 ...

[diff]
    tool = kdiff3
[merge]
    tool = kdiff3
[difftool "kdiff3"]
    cmd = kdiff3 \"$(cygpath -wla $LOCAL)\" \"$(cygpath -wla $REMOTE)\"
    trustExitCode = false
[mergetool "kdiff3"]
    cmd = kdiff3 \"$(cygpath -wla $BASE)\" \"$(cygpath -wla $LOCAL)\" \"$(cygpath -wla $REMOTE)\" -o \"$(cygpath -wla $MERGED)\"
    keepBackup = false
    trustExitCode = false
[mergetool]
    prompt = false
[difftool]
    prompt = false
like image 97
E.L. Avatar answered Oct 19 '22 11:10

E.L.


Simple answer is that you can't have a '~' in a git config file (apparently).

So replacing this line:

[mergetool "kdiff3"]
    path = ~/kdiff3.sh

With this:

[mergetool "kdiff3"]
    path = /home/mike.hadlow/kdiff3.sh

Made it work fine.

like image 37
Mike Hadlow Avatar answered Oct 19 '22 10:10

Mike Hadlow