Skip to content

Instantly share code, notes, and snippets.

@tonyarnold
Created March 6, 2019 22:35
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tonyarnold/41a2a5392bfd6d05fa1eb9ec89ad992b to your computer and use it in GitHub Desktop.
Save tonyarnold/41a2a5392bfd6d05fa1eb9ec89ad992b to your computer and use it in GitHub Desktop.
Git Tower & Sublime Merge Integration
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<array>
<dict>
<key>ApplicationIdentifier</key>
<string>com.sublimemerge</string>
<key>ApplicationName</key>
<string>Sublime Merge</string>
<key>DisplayName</key>
<string>Sublime Merge</string>
<key>LaunchScript</key>
<string>smerge.sh</string>
<key>Identifier</key>
<string>smerge</string>
<key>SupportsMergeTool</key>
<true/>
<key>SupportsDiffChangeset</key>
<false/>
</dict>
</array>
</plist>
#!/bin/sh
LOCAL="$1"
REMOTE="$2"
# Sanitize LOCAL path
if [[ ! "$LOCAL" =~ ^/ ]]; then
LOCAL=$(echo "$LOCAL" | sed -e 's/^\.\///')
LOCAL="$PWD/$LOCAL"
fi
# Sanitize REMOTE path
if [[ ! "$REMOTE" =~ ^/ ]]; then
REMOTE=$(echo "$REMOTE" | sed -e 's/^\.\///')
REMOTE="$PWD/$REMOTE"
fi
MERGING="$4"
BACKUP="/tmp/$(date +"%Y%d%m%H%M%S")"
CMD=`which smerge`
if [ ! -x "$SUBLIME_MERGE" ]; then
CMD=/usr/local/bin/smerge
fi
if [ ! -x "$CMD" ]; then
echo "The Sublime Merge tool smerge could not be located. Please install it from https://sublimemerge.com/." >&2
exit 128
fi
if [ -n "$MERGING" ]; then
BASE="$3"
MERGE="$4"
# Sanitize BASE path
if [[ ! "$BASE" =~ ^/ ]]; then
BASE=$(echo "$BASE" | sed -e 's/^\.\///')
BASE="$PWD/$BASE"
if [ ! -f "$BASE" ]; then
BASE=/dev/null
fi
fi
# Sanitize MERGE path
if [[ ! "$MERGE" =~ ^/ ]]; then
MERGE=$(echo "$MERGE" | sed -e 's/^\.\///')
MERGE="$PWD/$MERGE"
if [ ! -f "$MERGE" ]; then
# For conflict "Both Added", Git does not pass the merge param correctly in current versions
MERGE=$(echo "$LOCAL" | sed -e 's/\.LOCAL\.[0-9]*//')
fi
fi
sleep 1 # required to create different modification timestamp
touch "$BACKUP"
"$CMD" mergetool "${BASE}" "${LOCAL}" "${REMOTE}" -o "${MERGE}"
else
"$CMD" mergetool "${LOCAL}" "${REMOTE}"
fi
if [ -n "$MERGING" ]; then
# Check if the merged file has changed
if [ "$MERGE" -ot "$BACKUP" ]; then
exit 1
fi
fi
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment