Skip to content

Instantly share code, notes, and snippets.

@Fykec
Created August 28, 2013 11:44
Show Gist options
  • Save Fykec/6365125 to your computer and use it in GitHub Desktop.
Save Fykec/6365125 to your computer and use it in GitHub Desktop.
TextWrangler as git mergetool
[diff]
tool = "twdiff"
[difftool]
prompt = false
[difftool "twdiff"]
cmd = /usr/local/bin/twdiff --wait --resume "$LOCAL" "$REMOTE"
[merge]
tool = "twdiff"
[mergetool]
prompt = false
[mergetool "twdiff"]
cmd = /usr/local/bin/twdiff --wait --resume "$LOCAL" "$REMOTE"
@madamimadam
Copy link

madamimadam commented Apr 23, 2018

If you want mergetool to actually do the merge for you, you have to write the output to $MERGED. (Did this change sometime in the last 5 years?

In any case, here's a script that will work with bbedit/bbdiff or textwrangler/twdiff. You change the temp files it creates for $LOCAL and $REMOTE, then save both. If they are identical, then send it to $MERGED.

#!/usr/bin/env bash

if [ "$#" != "3" ]
then
    echo "Usage: bbmerge infile_1 infile_2 outfile"
    echo "Two temporary files will be created corresponding to infiles 1 & 2"
    echo "Save them when they match, and they will be written to outfile."
    echo "Original input files will remain untouched."
    exit 1
fi

infile_1="/tmp/`basename $1`.1"
infile_2="/tmp/`basename $2`.2"
merged_file=$3

cp "$1" "$infile_1"
cp "$2" "$infile_2"

 /usr/local/bin/bbdiff --wait --resume "$infile_1" "$infile_2"

if diff "$infile_1" "$infile_2"
then
    cp "$infile_1" "$merged_file"
    echo "Merge successful."
    rm "$infile_1" "$infile_2"
else
    echo "Files were not identical. Merge unsuccessful."
    rm "$infile_1" "$infile_2"
    exit 1
fi

And here is the updated gitconfig.

[merge]
    tool = "bbmerge"
[mergetool]
    prompt = false
[mergetool "bbmerge"]
    cmd = /usr/local/bin/bbmerge "$LOCAL" "$REMOTE" "$MERGED"

Of course, if you're using textwrangler, then just use twmerge and twdiff.

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