How to set Araxis as diff / merge tool for MSYS git? - windows

I'm trying to use Araxis Merge as my diff / merge tool for MSYSGit.
I found a few resources on the net:
On the Araxis site, they mention an "easy" way, but it implies a executables (araxisgitdiff.exe and araxisgitmerge.exe) that are not part of my distro.
I also found some info in gitguru, but the actual information re: Araxis is sparse at best, and I could not make anything out of that.
Finally, there was some info on an older stackoverflow post, but the suggested method doesn't work for me. That particular info was geared towards OS X. I "translated" to Windows as best as I could, but without success:
I created /bin/git-diff-driver.sh
#!/bin/sh
"/c/Program Files/Araxis/Araxis Merge/compare.exe" -title1:"$1 (repo version)" -title2:"$1 " -max "$2" "$5"
and edited gitconfig
[merge]
tool = araxismerge
[mergetool "araxismerge"]
cmd = "/c/Program Files/Araxis/Araxis Merge/compare.exe" -3 -merge -wait $LOCAL $BASE $REMOTE $MERGED
[diff]
external = "/bin/git-diff-driver.sh"
and the only result I get is:
$ git diff HEAD^ HEAD
external diff died, stopping at PowerEditor/src/Notepad_plus.cpp.
Edit:
I've also tried with the exe named as "c:/Program Files/Araxis/Araxis Merge/compare.exe" as suggested by one of the answers, with the same results.
Edit:
I've found that it can easily be set if you use TortoiseGit, but it seems to handle diff by itself and no settings from TortoiseGit give any indication on how to set up Araxis as a merge tool when diff is invoked from the command line.
Edit:
So, the question is: Is there anybody who successfully uses Araxis Merge to diff and merge stuff with MSYSGit, and if so, how do you it?

If you want to have 'git diff' always use araxis you can use the instructions in the help file, but if you want to have control to use 'git diff' as you normally would from the command line and 'git difftool' to engage the Araxis GUI.
Try adding the following to your git config::
[difftool "araxis"]
path = "/c/Program Files/Araxis/Araxis Merge/compare.exe"
renames = true
trustExitCode = true
[diff]
tool = araxis
stat = true
[mergetool "araxismergetool"]
cmd = 'C:\\Program Files\\Araxis\\Araxis Merge\\araxisgitmerge.exe' "$REMOTE" "$BASE" "$PWD/$LOCAL" "$PWD/$MERGED"
trustExitCode = false
[mergetool]
keepBackup = false
[merge]
tool = araxismergetool
stat = true

The documentation at araxis has been updated: http://www.araxis.com/merge/documentation-windows/integrating-with-other-applications#Git
I can use the configuration shown there without any modifications.

Right... I got it working, with msysgit version 1.6.3.2.1299.gee46c, under DOS or Git Bash, with an evaluation license for Araxis Merge 2009, v2009.3713:
The approach is to use the new git difftool and git mergetool, instead of plain diff.
First, let's setup some scripts for those diff and merge tool
C:\>git config --global diff.tool adifftool
C:\>git config --global diff.external git-difftool--helper
C:\>git config --global difftool.adifftool.cmd "difftool.sh \"$LOCAL\" \"$REMOTE\" \"$MERGED\""
C:\>git config --global difftool.prompt false
Notes:
by setting diff.external to the Git script git-difftool--helper, I will use difftool even when I will type 'git diff'.
do not forget to pass $MERGED to your difftool script: that is the only variable with the real name of the file being diff'ed. $LOCAL and $REMOTE are temporary names.
For the merge tool, you would set the following global values:
C:\>git config --global merge.tool amergetool
C:\>git config --global mergetool.amergetool.cmd "mergetool.sh \"$PWD/$LOCAL\" \"$PWD/$BASE\" \"$PWD/$REMOTE\" \"$PWD/$MERGED\""
C:\>git config --global mergetool.prompt false
By setting those tools to some shell scripts, you will be able to switch tools from within those scripts.
Another approach is to name your tools (mergetool.araxis.cmd, mergetool.winmerge.cmd, ...) and to specify the right tool in the diff.tool or merge.tool setting.
Create difftool.sh and mergetool.sh in a directory referenced by your global environment variable PATH. They will work even from DOS (and they are sh -- shell -- scripts)
difftool.sh
#!/bin/sh
echo Launching Araxis Merge.exe: $3
t1="'$3 (from)'"
t2="'(to)'"
"C:/Program Files/Araxis/Araxis Merge/Compare.exe" -max -nowait -2 -title1:${t1} -title2:${t2} "$1" "$2"
Notes:
Impossible to have -title1:"someTitle With Space"... only title without space does work..., so for now, try it without any 'titleN' option.
Got it! You cannot pass the title value directly to the -title option, you need to set it to a local variable, with "' '" quotes combinations (the double quotes will disappear during the shell script execution, leaving the simple quotes, allowing spaces within a title!)
$3 represent the real name and not some temporary file name for diff purpose. Hence the use of $3 within the title1 option, with space in it.
git diff HEAD^ HEAD would not work in DOS session: only git diff "HEAD^" HEAD would.
mergetool.sh
#!/bin/sh
# Passing the following parameters to mergetool:
# local base remote merge_result
alocal=$1
base=$2
remote=$3
result=$4
t1="'$4 (current branch)'"
t2="'(common ancestor)'"
t3="'(to be merged)'"
if [ -f $base ]
then
"C:/Program Files/Araxis/Araxis Merge/Compare.exe" -max -wait -merge -3 -a2 -title1:${t1} -title2:${t2} -title3:${t3} "$alocal" "$base" "$remote" "$result"
else
"C:/Program Files/Araxis/Araxis Merge/Compare.exe" -max -wait -merge -3 -a2 -title1:${t1} -title2:${t2} -title3:${t3} "$alocal" "$result" "$remote" "$result"
fi
I am not sure I those scripts do work properly when multiple files are involved (multiple diffs, multiple files to be merged).
Just tested it: it works, and Araxis compare.exe does open one tab per file to diff or merge.
Give it a try and let us know ;)

I think that you need to be a bit more careful with your escaping in your .gitconfig.
Unfortunately, due to the way the config variable is expanded and evaled, your string needs to be an valid shell command which is then 'git config' escaped.
Try something like this:
[mergetool "araxismerge"]
cmd = \"/c/Program Files/Araxis/Araxis Merge/compare.exe\" -3 -merge -wait \"$LOCAL\" \"$BASE\" \"$REMOTE\" \"$MERGED\"
Yes, not very pretty, I know. It's one of the cases where using git config directly is actually easier.
git config --global mergetool.araxismerge.cmd '"/c/Program Files/Araxis/Araxis Merge/compare.exe" -3 -merge -wait "$LOCAL" "$BASE" "$REMOTE" "$MERGED"'

I struggled with this problem for quite a while, and now I finally can say, that all suggested dirty hacks (like intermediate shell scripts) are rather unnecessary =D. Thing is, all of the latest versions of MSYSGit (I have 1.6.4) support Araxis Merge (I have 2008) out of the box. It comes at no surprise, that internally it's called "araxis". So, all that you need is to set
[merge]
tool = araxis
in your .gitconfig. Also you have to include Araxis folder into your PATH environment variable (MSYSGit looks for Compare.exe).
For a good measure, other Git settings related to "araxis" mergetool, that you could have configured (especially, if you happen to choose exactly that name, as did some people on this page), should all be removed. That includes everything under [mergetool "araxis"] section. Be sure to remove them from all configs (system, global, and repository), otherwise, they might interfere with normal "internal tool" behavior.
In any case, if you're interested in how MSYSGit will start your Araxis Merge, or wondering what other mergetools it supports out of the box, the place to look is \share\git-gui\lib\mergetool.tcl script in your MSYSGit installation folder.
PS. You might be able to avoid setting PATH environment variable, by configuring mergetool.araxis.path in .gitconfig. Personally, I never bothered to do so, since
I use Araxis Merge from command line anyway.
Specifying directory path in .gitconfig (especially the one like "C:\Program Files\Araxis\Araxis Merge\", which contains spaces) can prove hard to be done correctly, since it is prone to backslash/forwardslash issues, that plague MSYSGit.
PPS. All of the above applies to making Araxis your difftool, too. I.e, you need to add
[diff]
tool = araxis
and remove anything else in [difftool "araxis"] section, if you have it in your config (don't forget to set up PATH, though).

You could try to follow the script mentioned in my answer about diffMerge (for Windows) and see if it works.
The executable path could be better expressed with:
#!/bin/sh
"C:/Program Files/Araxis/Araxis Merge/compare.exe" -title1:"$1 (repo version)" -title2:"$1 " -max "$2" "$5"

One way I found to do it "simply" is to install TortoiseGit and set the diff / merge tools in TortoiseGit options.
However, this does not address the issue if you want to diff from the command line.

Since I've been bitten to customised git differs/mergers, I thought I would try to fix this one for once and for all. I got to the point where AraxisMerge started, but without the titles of the tabs. So that will be left as an exercise for the reader :)
Observations and comments:
I didn't have AraxisMerge, so I downloaded it and got a free 30-days evaluation license to try it out with. This version (7.0 it seems) comes with araxisgitdiff.exe, and the link with instructions you send works. So that would be option #1: upgrade araxis merge.
Since I'm working from CMD.EXE, 'git diff HEAD HEAD^' does not work. The '^' needs to be escaped to 'git diff HEAD "HEAD^"'.
For my own work I use kdiff3 as a free replacement on Windows which works reasonably well (it helps that it is supported by default by git)
Starting with the git-diff-driver.sh gave the same error to me. After changing the script to only contain 'echo', this did not change. So the error is independent from the contents of the script.
Then I removed the '/bin' part from .gitconfig, so the line becomes
external = "git-diff-driver.sh"
...and this started to work: it started the merger, but it does not escape the '(repo) ' part correctly. As a workaround I got it working without the titles with:
#!/bin/sh
"/c/Program Files/Araxis/Araxis Merge/compare.exe" -max "$2" "$5"
Good luck!

Related

I want to change the code editor configuration for my macOS terminal, but my commands are no longer working

To briefly summarize, I am learning version control and a part of my course is configuring a code editor to my terminal.
This was easy enough initially, however after I changed my code editor from atom to sublime text in an attempt to fix a git commit issue I found that sublime text was even more problematic than atom.
While trying to switch back to atom, I have found that none of the commands I was given to remove "subl -n -w" from my core.editor settings are working now.
git config --global --replace-all core.editor "editor-config-code"
git config --global --unset-all core.editor
When running "git var -l", this is the result I get:
credential.helper=osxkeychain
filter.lfs.smudge=git-lfs smudge -- %f
filter.lfs.process=git-lfs filter-process
filter.lfs.required=true
filter.lfs.clean=git-lfs clean -- %f
user.name=Xxx Xxxxxxxx
user.email=xxxxxxxx#yahoo.com
core.editor=atom
core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true
core.ignorecase=true
core.precomposeunicode=true
core.editor=subl -n -w
GIT_COMMITTER_IDENT=Tim Sherwood <tsher004#yahoo.com> 1574301511 -0500
GIT_AUTHOR_IDENT=Tim Sherwood <tsher004#yahoo.com> 1574301511 -0500
GIT_EDITOR=subl -n -w
GIT_PAGER=less
. . . and this is what comes up when I execute "git commit"
hint: Waiting for your editor to close the file... subl -n -w: subl: command not found
error: There was a problem with the editor 'subl -n -w'.
Please supply the message using either -m or -F option.
Ideally this command should open the atom code editor installed on my Mac and present me with the option to supply a message for the commit. So far I have not had much luck with this.
Any help would be appreciated.
From the git-var documentation:
The order of preference is the $GIT_EDITOR environment variable, then core.editor configuration, then $VISUAL, then $EDITOR, and then the default chosen at compile time, which is usually vi.
Hence, you need to unset or edit the $GIT_EDITOR environment variable since it has precedence over core.editor.
Also, take note that your output for git -var l lists core.editor twice. So you should really sort that out in either ~/.gitconfigor your local .git/config.

How to use opendiff and git diff and not needing to install the whole Xcode app?

After upgrading to MacOS Mojave, my git and opendiff stopped working (my opendiff is usually invoked by git diff).
I was able to get git working, by using the following two lines:
xcode-select --install
sudo xcode-select -switch /Library/Developer/CommandLineTools
but opendiff and git diff still doesn't work. It seems one solution is to install the Xcode app, which is huge (said to be taking up 10GB on the hard drive). I checked Spotlight and typed FileMerge, and was able to find it, which should be the same as opendiff, and was able to use ps ax to find the path /Applications/Xcode.app/Contents/Applications/FileMerge.app/Contents/MacOS/FileMerge. But then, using git diff, I actually used a bash script to invoke
#!/bin/sh
/usr/bin/opendiff "$2" "$5" -merge "$1" | cat
(see this github article about how to set up git-diff-cmd.sh)
so I changed that second line to:
/Applications/Xcode.app/Contents/Applications/FileMerge.app/Contents/MacOS/FileMerge "$2" "$5" -merge "$1" | cat
but it doesn't work. So FileMerge exists, and it looks like opendiff is FileMerge. Can git diff be made to work without needing to install the whole Xcode app?
This may seem like a hack, and in fact it seems like it is using an existing installation of XCode:
I did
cd /Applications/Xcode.app
find . -iname '*opendiff*'
and was able to find
./Contents/Developer/usr/bin/opendiff
./Contents/Developer/usr/libexec/git-core/mergetools/opendiff
The first file is a binary file, and the second one is actually a script, so I changed my bash script git-diff-cmd.sh to the following:
#!/bin/sh
/Applications/Xcode.app/Contents/Developer/usr/bin/opendiff "$2" "$5" -merge "$1" | cat
and git diff can successfully invoke opendiff to do a visual diff.
Can git diff be made to work without needing to install the whole XCode app?
Install the whole BBEdit app instead. It’s small and efficient and does a very nice visual diff.

Cygwin: Git stash -> Cannot save the current index state

I'm using cygwin under Windows to do some command line stuff. One of the commands I use sometimes is git stash. Since few weeks I always get this error when I use it: Cannot save the current index state
I also tried it in other projects, so it is no project related issue. The history is not broken or something like that. I don't use it often so I don't know when the issue started.
The error is thrown on line 110 of the git-stash file. That's why I debugged the two lines before.
$(printf 'index on %s\n' "$msg" |
git commit-tree $i_tree -p $b_commit)
When I echo the first command it outputs my last commit. This seems ok. When I output both commands piped it is empty, so maybe something is wrong with "git commit-tree $i_tree -p $b_commit". I google a long time but was not able to find a solution to this issue.
Cygwin Git version: 2.14.1
Cygwin x64 version: 2.8.2(0.313/5/3)
First, check if the issue persists with bash (the bash packaged with Git). Make sure to set your PATH in order to:
no include cygwin
include git/bin, git/usr/bin, git/mingw64/bin: see this example.
Working with a simplified path (for testing purposes) is important to make sure there is no side-effect from any other software.
Second, try and add a git status in the git stash critical lines, to see if the Git repo status reveal anything suspicious.

How to configure kdiff3 instead of emerge as a git mergetool?

I have Git on mac OSX Snow Leopard and I tried to edit my merge and diff tool to use kdiff3 instead of emerge.
But when I try to use it does not launch the GUI of kdiff and keeps me with a cmd based interface.
My setting in gitconfig are:
[merge]
tool = kdiff3
[mergetool "kdiff3"]
cmd = /Applications/kdiff3.app/Contents/MacOS/kdiff3
args = $base $local $other -o $output
trustExitCode = false
[diff]
tool = kdiff3
[difftool "kdiff3"]
cmd = /Applications/kdiff3.app/Contents/MacOS/kdiff3
args = $base $local $other -o $output
trustExitCode = false
There is obviously something missing but what did I do wrong ?
Recent Git versions have built-in support for kdiff3, so there's no need to configure it manually using the generic cmd and args settings. Instead do:
$ git config --global merge.tool kdiff3
And if kdiff3 is not in your PATH environment also do:
$ git config --global mergetool.kdiff3.path /Applications/kdiff3.app/Contents/MacOS/kdiff3
This makes git mergetool launch kdiff3. Note that there is no way to configure Git to automatically launch your merge tool after a manual merge that has conflicts.
In case you really want to see how Git is calling kdiff3 internally, take a look at the built-in mergetool configuration for kdiff3.
Edit: For Beyond Compare 4, which now also supports Mac OS X, simply exchange kdiff3 with bc3 (yes, "3") and adjust the path in the above lines. Starting with Git 2.2.0 you'll be able to use bc as an alias for bc3 so that you do not have to care about the version number.
Recent Git versions have built-in support for kdiff3
Yes, but only Git 2.12 (Q1 2017) will allow those built-in tools to trust their exit code.
See commit 2967284, commit 7c10605 (29 Nov 2016) by David Aguilar (davvid).
(Merged by Junio C Hamano -- gitster -- in commit c4a44e2, 16 Dec 2016)
mergetool: honor mergetool.$tool.trustExitCode for built-in tools
Built-in merge tools contain a hard-coded assumption about whether or not a tool's exit code can be trusted to determine the success or failure of a merge.
Tools whose exit codes are not trusted contain calls to check_unchanged() in their merge_cmd() functions.
A problem with this is that the trustExitCode configuration is not honored for built-in tools.
Teach built-in tools to honor the trustExitCode configuration.
(See kdiff3)
Extend run_merge_cmd() so that it is responsible for calling check_unchanged() when a tool's exit code cannot be trusted.
Remove check_unchanged() calls from scriptlets since they are no longer responsible for calling it.

Use Xcode 4 as Git difftool

I want to use Xcode 4's "Version Editor" view as my standard difftool for Git.
In other words, I want to be able to set this option:
git config --global diff.external <XCODE>
And have the diff open in Xcode's diff viewer (because it's cool).
Is this possible? How?
Sadly not possible. Here's hoping Apple changes that someday though.
I'm guessing you already know the following, but for the benefit of others who may not, you can use Apple's FileMerge application instead for a similar, albeit somewhat lesser, experience with a command like:
git difftool path/to/file
My git defaults to using FileMerge as the difftool, but you can configure it explicitly with:
git config --global diff.tool opendiff
(This stops git from listing the candidate tools every time too.) I also like to disable git's difftool pre-launch prompting:
git config --global difftool.prompt false
It is possible to configure git so that git diff will invoke FileMerge as well, or instead. (I prefer to just leave git diff the way it is myself.) If you want that you first need to create a shell script to map the appropriate arguments to opendiff:
#!/bin/sh
/usr/bin/opendiff "$2" "$5" -merge "$1"
and then run
git config --global diff.external /path/to/shell/script

Resources