Skip to content
Create a gist now

Instantly share code, notes, and snippets.

Cygwin Git: wrappers for diffmerge, winmerge, and p4merge
#!/bin/sh
# Use SourceGear DiffMerge as mergetool for git in cygwin.
# git config --global mergetool.diffmerge.cmd "diffmergetool.sh \"\$LOCAL\" \"\$REMOTE\" \"\$BASE\" \"\$MERGED\""
# git config --global mergetool.diffmerge.trustExitCode false
# git difftool -t diffmerge branch1..branch2
# Reference: http://www.tldp.org/LDP/abs/abs-guide.pdf
library=githelperfunctions.sh
#[ -f $library ] && . $library
. $library
echo Launching DiffMerge.exe - diffmerge-diff.sh:
set_path_vars "$1" "$2" "$3" "$4"
echo "$diffmergewinpath" -t1=FROM_VERSION -t2=TO_VERSION --caption=$caption $localwinpath $remotewinpath
"$diffmergewinpath" -t1=FROM_VERSION -t2=TO_VERSION --caption="$caption" "$localwinpath" "$remotewinpath"
#!/bin/sh
# Use SourceGear DiffMerge as mergetool for git in cygwin.
# git config --global mergetool.diffmerge.cmd "diffmergetool.sh \"\$LOCAL\" \"\$REMOTE\" \"\$BASE\" \"\$MERGED\""
# git config --global mergetool.diffmerge.trustExitCode false
# git mergetool -t diffmerge
# Reference: http://www.tldp.org/LDP/abs/abs-guide.pdf
library=githelperfunctions.sh
#[ -f $library ] && . $library
. $library
echo Launching DiffMerge.exe - diffmerge-merge.sh:
set_path_vars "$1" "$2" "$3" "$4"
"$diffmergewinpath" --merge -t1=FROM_VERSION -t2=MERGED -t3=TO_VERSION --result="$mergedwinpath" --caption="$caption" "$localwinpath" "$basewinpath" "$remotewinpath"
unix2dos "$merged"
# Helper functions
convert_path () {
file=$1
if [ "$file" == '/dev/null' ] || [ ! -e "$file" ]
then
file="/tmp/nulla"
`echo "">$file`
fi
echo `cygpath -w -a "$file"`
}
set_path_vars () {
local=$1
remote=$2
base=$3
merged=$4
echo ========= Cygwin paths =======
echo "LOCAL : $local"
echo "REMOTE : $remote"
echo "BASE : $base"
echo "MERGED : $merged"
localwinpath=$(convert_path "$local")
remotewinpath=$(convert_path "$remote")
basewinpath=$(convert_path "$base")
mergedwinpath=$(convert_path "$merged")
echo ========= Win paths =======
echo "LOCAL : $localwinpath"
echo "REMOTE : $remotewinpath"
echo "BASE : $basewinpath"
echo "MERGED : $mergedwinpath"
caption=`basename "$merged"`
diffmergewinpath="C:/Program Files/SourceGear/DiffMerge/DiffMerge.exe"
winmergewinpath="C:/Program Files/WinMerge/WinMergeU.exe"
p4mergewinpath="C:/Program Files/Perforce/p4merge.exe"
}
#!/bin/sh
# Use p4merge as mergetool for git in cygwin.
# git config --global difftool.p4merge.cmd "p4merge-diff.sh \"\$LOCAL\" \"\$REMOTE\" \"\$BASE\""
# git config --global mergetool.p4merge.trustExitCode false
# git difftool -t p4merge branch1..branch2
# Reference: http://www.tldp.org/LDP/abs/abs-guide.pdf
# Reference: http://p4merge.org/docs/manual/CommandLine.html
library=githelperfunctions.sh
#[ -f $library ] && . $library
. $library
echo Launching p4merge.exe - p4merge-diff.sh:
set_path_vars "$1" "$2" "$3" "$4"
#"$p4mergewinpath" /dl "LOCAL.$caption" /dr "TO_VERSION.$caption" "$localwinpath" "$remotewinpath"
"$p4mergewinpath" "$localwinpath" "$remotewinpath"
#!/bin/sh
# Use p4merge as mergetool for git in cygwin.
# git config --global mergetool.p4merge.cmd "p4merge-merge.sh \"\$LOCAL\" \"\$REMOTE\" \"\$BASE\" \"\$MERGED\""
# git config --global mergetool.p4merge.trustExitCode false
# git mergetool -t diffmerge
# Reference: http://www.tldp.org/LDP/abs/abs-guide.pdf
# Reference: http://p4merge.org/docs/manual/CommandLine.html
library=githelperfunctions.sh
#[ -f $library ] && . $library
. $library
echo Launching p4merge.exe - p4merge-merge.sh:
set_path_vars "$1" "$2" "$3" "$4"
# -- use p4mergeU conflictFile
"$p4mergewinpath" "$mergedwinpath"
#!/bin/sh
# Use winmerge as mergetool for git in cygwin.
# git config --global difftool.winmerge.cmd "winmerge-diff.sh \"\$LOCAL\" \"\$REMOTE\" \"\$BASE\""
# git config --global mergetool.winmerge.trustExitCode false
# git difftool -t winmerge branch1..branch2
# Reference: http://www.tldp.org/LDP/abs/abs-guide.pdf
# Reference: http://winmerge.org/docs/manual/CommandLine.html
library=githelperfunctions.sh
#[ -f $library ] && . $library
. $library
echo Launching winmerge.exe - winmerge-diff.sh:
set_path_vars "$1" "$2" "$3" "$4"
"$winmergewinpath" /dl "LOCAL.$caption" /dr "TO_VERSION.$caption" "$localwinpath" "$remotewinpath"
#!/bin/sh
# Use winmerge as mergetool for git in cygwin.
# git config --global mergetool.winmerge.cmd "winmerge-merge.sh \"\$LOCAL\" \"\$REMOTE\" \"\$BASE\" \"\$MERGED\""
# git config --global mergetool.winmerge.trustExitCode false
# git mergetool -t diffmerge
# Reference: http://www.tldp.org/LDP/abs/abs-guide.pdf
# Reference: http://winmerge.org/docs/manual/CommandLine.html
library=githelperfunctions.sh
#[ -f $library ] && . $library
. $library
echo Launching winmerge.exe - winmerge-merge.sh:
set_path_vars "$1" "$2" "$3" "$4"
# -- use WinMergeU conflictFile
"$winmergewinpath" "$mergedwinpath"
@stremblay

Hi! I got your scripts to use p4merge with git in Cygwin.

I noticed p4merge pops up an error message when merging conflicts. I found the problem.

At line 21 of winmerge-merge.sh the line

"$p4mergewinpath" "$mergedwinpath"

But, p4merge requires 4 parameters to merge files. So instead it should be:

"$p4mergewinpath" "$basewinpath" "$localwinpath" "$remotewinpath" "$mergedwinpath"

That fixed it for me.

Regards,

Stephane

@techyourchance

You made my day!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.