Skip to content

Instantly share code, notes, and snippets.

@jaburns
Last active April 25, 2021 05:21
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jaburns/4e9f18a7fe3294970feaa69e4892a681 to your computer and use it in GitHub Desktop.
Save jaburns/4e9f18a7fe3294970feaa69e4892a681 to your computer and use it in GitHub Desktop.
Using VS as mergetool on WSL
[merge]
tool = vs
[mergetool "vs"]
cmd = /home/XXX/win_merge.sh merge $LOCAL $REMOTE $BASE $MERGED
trustExitCode = false
[mergetool]
keepBackup = false
[diff]
tool = vs
[difftool "vs"]
cmd = /home/XXX/win_merge.sh diff $LOCAL $PWD/$REMOTE
#!/usr/bin/env sh
VS_MERGE='/mnt/c/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/IDE/CommonExtensions/Microsoft/TeamFoundation/Team Explorer/vsDiffMerge.exe'
get_filename() {
echo "$1" | sed 's:.*/::'
}
resolve_path() {
pushd "$(dirname "$1")" >/dev/null
local base_path="$(pwd -P | sed 's:/mnt/::;s_/_:/_;s:/:\\:g')"
echo "$base_path\\$(get_filename "$1")"
popd >/dev/null
}
do_diff() {
local tmp_local="$(get_filename $1)"
local remote="$(resolve_path "$2")"
cp "$1" "/mnt/c/Windows/Temp/$tmp_local"
"$VS_MERGE" /t "C:\\Windows\\Temp\\$tmp_local" "$remote" Source Target
}
case "$1" in
diff) do_diff "$2" "$3" ;;
merge) "$VS_MERGE" /m "$2" "$3" "$4" "$5" ;;
esac
@jaburns
Copy link
Author

jaburns commented Nov 15, 2017

The .gitconfig above specifies stuff to add to your ~/.gitconfig file. Replace the paths starting with /home/XXX to wherever you end up dropping win_merge.sh, but they must be absolute paths.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment