Skip to content

Instantly share code, notes, and snippets.

@sc0ttkclark
Last active November 23, 2022 15:41
Show Gist options
  • Save sc0ttkclark/07f293e092fbb04d57dac0c2ed61c033 to your computer and use it in GitHub Desktop.
Save sc0ttkclark/07f293e092fbb04d57dac0c2ed61c033 to your computer and use it in GitHub Desktop.
WebStorm.app (Standalone) Mac integration with Tower.app for diff and merge

WebStorm.app (Standalone) Mac integration with Tower.app for diff and merge

How to use this

  1. Add CompareTools.plist and webstorm.sh files in the ~/Library/Application Support/com.fournova.Tower3/CompareTools/ directory
  2. Run chmod +x ~/Library/Application\ Support/com.fournova.Tower3/CompareTools/webstorm.sh
  3. Go into Tower.app Preference > Git Config > Select "WebStorm" for "Diff tool" and "Compare tool", you can optionally enable "Perform directory diff"

Other variations

Credits

While I went and figured out how to do all of this, this integration is based on the one I found for Beyond Compare's beta integration: https://github.com/tednaleid/git-tower-beyond-compare-shim

Based on my original gist for PhpStorm + Tower.app diff integration: https://gist.github.com/sc0ttkclark/213fe88f9eacbd5ae58a

Also used the forked gist: https://gist.github.com/dsandor/19bfa4afbfc43cb3aff6f62167a41485

The difference with this one from the fork from @dsandor is that this one is updated with the latest changes from the original gist.

<?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.jetbrains.WebStorm</string>
<key>ApplicationName</key>
<string>WebStorm</string>
<key>DisplayName</key>
<string>WebStorm</string>
<key>LaunchScript</key>
<string>webstorm.sh</string>
<key>Identifier</key>
<string>webstorm</string>
<key>SupportsMergeTool</key>
<true/>
<key>SupportsDiffChangeset</key>
<true/>
</dict>
</array>
</plist>
#! /usr/bin/env bash
# Shell script shim to let WebStorm.app to integrate with Tower.app
#
# Tower.app gives us these parameters:
LOCAL="$1"
REMOTE="$2"
APPLICATION_PATH=/Applications/WebStorm.app
CMD="$APPLICATION_PATH/Contents/MacOS/webstorm"
# 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")"
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" merge "$LOCAL" "$REMOTE" "$BASE" "$MERGE"
else
"$CMD" diff "$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