#!/bin/sh

merge_ts() {
    stat -f "%m" "$MERGED"
}

GF_MTIME_START=$(merge_ts)

GF_TOOL_PATH="/Applications/Kaleidoscope.app/Contents/MacOS/ksdiff"
if [ ! -x "$GF_TOOL_PATH" ]; then
    GF_TOOL_PATH="$HOME/Applications/Kaleidoscope.app/Contents/MacOS/ksdiff"
fi
if [ ! -x "$GF_TOOL_PATH" ]; then
    GF_TOOL_PATH="/usr/local/bin/ksdiff"
fi

"$GF_TOOL_PATH" \
    --merge \
    --output "$MERGED" \
    --base "$BASE" \
    -- "$LOCAL" --snapshot "$REMOTE" --snapshot

GF_MTIME_END=$(merge_ts)

if [ $GF_MTIME_END -gt $GF_MTIME_START ]; then
    exit 0
fi

exit 1
