# [PATCH] mergetool: make Apple's FileMerge available as a merge_tool

6 messages from 2007-06-17 to 2007-06-18. Participants: Steffen Prohaska, Theodore Tso, Scott Lamb.
Thread: https://gitlist.dev/t/8629

## Steffen Prohaska, 2007-06-17 15:59

Subject: [PATCH] mergetool: make Apple's FileMerge available as a merge_tool
Message-ID: <11820959413590-git-send-email-prohaska@zib.de>
URL: https://gitlist.dev/e/11820959413590-git-send-email-prohaska%40zib.de

```
Apple's developer tools include the application FileMerge,
which supports graphical three way merges with ancestor.
This patch makes the tool available through git-mergetool.

FileMerge is assumed to be installed at its default location.

Signed-off-by: Steffen Prohaska <prohaska@zib.de>
---
 Documentation/git-mergetool.txt |    3 ++-
 git-mergetool.sh                |   20 ++++++++++++++++++++
 2 files changed, 22 insertions(+), 1 deletions(-)

diff --git a/Documentation/git-mergetool.txt b/Documentation/git-mergetool.txt
index 6c32c6d..ff4cdf2 100644
--- a/Documentation/git-mergetool.txt
+++ b/Documentation/git-mergetool.txt
@@ -25,7 +25,8 @@ OPTIONS
 -t or --tool=<tool>::
 	Use the merge resolution program specified by <tool>.
 	Valid merge tools are:
-	kdiff3, tkdiff, meld, xxdiff, emerge, vimdiff, gvimdiff, and opendiff
+	kdiff3, tkdiff, meld, xxdiff, emerge, vimdiff, gvimdiff, opendiff,
+	and FileMerge
 +
 If a merge resolution program is not specified, 'git mergetool'
 will use the configuration variable merge.tool.  If the
diff --git a/git-mergetool.sh b/git-mergetool.sh
index 7b66309..abe2a97 100755
--- a/git-mergetool.sh
+++ b/git-mergetool.sh
@@ -258,6 +258,16 @@ merge_file () {
 	    status=$?
 	    save_backup
 	    ;;
+	*FileMerge)
+	    touch "$BACKUP"
+	    if base_present; then
+		$merge_tool -left "$LOCAL" -right "$REMOTE" -ancestor "$BASE" -merge "$path" | cat
+	    else
+		$merge_tool -left "$LOCAL" -right "$REMOTE" -merge "$path" | cat
+	    fi
+	    check_unchanged
+	    save_backup
+	    ;;
     esac
     if test "$status" -ne 0; then
 	echo "merge of $path failed" 1>&2
@@ -326,6 +336,9 @@ if test -z "$merge_tool" ; then
         merge_tool_candidates="$merge_tool_candidates vimdiff"
     fi
     merge_tool_candidates="$merge_tool_candidates opendiff emerge vimdiff"
+    if test $(uname) = "Darwin" ; then
+    	merge_tool_candidates="/Developer/Applications/Utilities/FileMerge.app/Contents/MacOS/FileMerge $merge_tool_candidates"
+    fi
     echo "merge tool candidates: $merge_tool_candidates"
     for i in $merge_tool_candidates; do
         if test $i = emerge ; then
@@ -357,6 +370,13 @@ case "$merge_tool" in
 	    exit 1
 	fi
 	;;
+    *FileMerge)
+	merge_tool=/Developer/Applications/Utilities/FileMerge.app/Contents/MacOS/FileMerge
+	if ! test -x $merge_tool ; then
+	    echo "FileMerge is not available"
+	    exit 1
+	fi
+	;;
     *)
 	echo "Unknown merge tool: $merge_tool"
 	exit 1
-- 
1.5.2.2.252.gbc777-dirty

```

## Steffen Prohaska, 2007-06-17 16:13

Subject: Re: [PATCH] mergetool: make Apple's FileMerge available as a merge_tool
Message-ID: <B12626B9-766E-4EA4-888F-B3E2DA889D15@zib.de>
URL: https://gitlist.dev/e/B12626B9-766E-4EA4-888F-B3E2DA889D15%40zib.de
In-Reply-To: <11820959413590-git-send-email-prohaska@zib.de>

```

On Jun 17, 2007, at 5:59 PM, Steffen Prohaska wrote:

> Apple's developer tools include the application FileMerge,
> which supports graphical three way merges with ancestor.
> This patch makes the tool available through git-mergetool.
>
> FileMerge is assumed to be installed at its default location.

Hmm, now I found out that opendiff, which was already available
as an option, actually launches FileMerge.

I wasn't aware of this fact. git-mergetool proposed to use vimdiff
although I had preferred the graphical application FileMerge, which
would have been launched by opendiff.

Don't know if my patch makes any sense. Probably a note in the
documentation that opendiff launches the GUI would be nice.

	Steffen

```

## Theodore Tso, 2007-06-17 18:12

Subject: Re: [PATCH] mergetool: make Apple's FileMerge available as a merge_tool
Message-ID: <20070617181200.GA15218@thunk.org>
URL: https://gitlist.dev/e/20070617181200.GA15218%40thunk.org
In-Reply-To: <B12626B9-766E-4EA4-888F-B3E2DA889D15@zib.de>

```
On Sun, Jun 17, 2007 at 06:13:11PM +0200, Steffen Prohaska wrote:
> 
> Hmm, now I found out that opendiff, which was already available
> as an option, actually launches FileMerge.

Yep.

> I wasn't aware of this fact. git-mergetool proposed to use vimdiff
> although I had preferred the graphical application FileMerge, which
> would have been launched by opendiff.

Do you know of a way of determining whether or not under MacOS X, a
program can easily determine whether or not the user is sitting in
front of the graphical display, as opposed to coming in via an SSH
connection?

If so, we could use that under MacOS to make the defaults be to use
opendiff under those circumstances.

Realistically, though, past a certain point we can only be so smart
with the hueristics.  If you know what you want, you should really set
the merge.tool config option in your ~/.gitconfig file, and be done
with it.

> Don't know if my patch makes any sense. Probably a note in the
> documentation that opendiff launches the GUI would be nice.

Maybe a change so that opendiff is listed as "opendiff (aka
FileMerge)", perhaps?

						- Ted

```

## Steffen Prohaska, 2007-06-17 19:20

Subject: Re: [PATCH] mergetool: make Apple's FileMerge available as a merge_tool
Message-ID: <42FEB11E-426D-4B44-9E7E-0E35032CB1B0@zib.de>
URL: https://gitlist.dev/e/42FEB11E-426D-4B44-9E7E-0E35032CB1B0%40zib.de
In-Reply-To: <20070617181200.GA15218@thunk.org>

```

On Jun 17, 2007, at 8:12 PM, Theodore Tso wrote:

> On Sun, Jun 17, 2007 at 06:13:11PM +0200, Steffen Prohaska wrote:
>
>> I wasn't aware of this fact. git-mergetool proposed to use vimdiff
>> although I had preferred the graphical application FileMerge, which
>> would have been launched by opendiff.
>
> Do you know of a way of determining whether or not under MacOS X, a
> program can easily determine whether or not the user is sitting in
> front of the graphical display, as opposed to coming in via an SSH
> connection?

this might do the job:

--- SNIP ---
#! /bin/sh

pid=$$

while [ $pid -ne 1 ] ; do
     command=$(ps -p $pid | tail -n 1 | cut -b 27-)
     echo $command | grep -q sshd && { echo "ssh" ; exit ; }
     echo $command | grep -q Terminal && { echo "local" ; exit ; }
     pid=$(ps -O ppid -p $pid | tail -n 1 | cut -b 6-11)
done

echo "unknown"
--- SNIP ---


> If so, we could use that under MacOS to make the defaults be to use
> opendiff under those circumstances.
>
> Realistically, though, past a certain point we can only be so smart
> with the heuristics.  If you know what you want, you should really set
> the merge.tool config option in your ~/.gitconfig file, and be done
> with it.

Well, I'm done with it. I learned that opendiff and FileMerge are the
same, which I wasn't aware of before.


>> Don't know if my patch makes any sense. Probably a note in the
>> documentation that opendiff launches the GUI would be nice.
>
> Maybe a change so that opendiff is listed as "opendiff (aka
> FileMerge)", perhaps?

perhaps. It wouldn't make things worse.

	Steffen

```

## Scott Lamb, 2007-06-18 09:39

Subject: Re: [PATCH] mergetool: make Apple's FileMerge available as a merge_tool
Message-ID: <467652BC.4050900@slamb.org>
URL: https://gitlist.dev/e/467652BC.4050900%40slamb.org
In-Reply-To: <42FEB11E-426D-4B44-9E7E-0E35032CB1B0@zib.de>

```
Steffen Prohaska wrote:
> 
> On Jun 17, 2007, at 8:12 PM, Theodore Tso wrote:
>> Do you know of a way of determining whether or not under MacOS X, a
>> program can easily determine whether or not the user is sitting in
>> front of the graphical display, as opposed to coming in via an SSH
>> connection?
> 
> this might do the job:
> 
> --- SNIP ---
> #! /bin/sh
> 
> pid=$$
> 
> while [ $pid -ne 1 ] ; do
>     command=$(ps -p $pid | tail -n 1 | cut -b 27-)
>     echo $command | grep -q sshd && { echo "ssh" ; exit ; }
>     echo $command | grep -q Terminal && { echo "local" ; exit ; }
>     pid=$(ps -O ppid -p $pid | tail -n 1 | cut -b 6-11)
> done
> 
> echo "unknown"
> --- SNIP ---

I propose a simpler test:

    if [ -n "$TERM_PROGRAM" ]; then
        echo local
    else
        echo remote
    fi

This environment variable seems to be set by Terminal.app and even two
alternatives I just tried (iTerm.app and GLterm.app). It's not
transmitted across ssh unless you stick an AcceptEnv in sshd_config.

About the only time it would fail is logging in via local xterm. I'd
guess few people do that, and determining if xterm is local or not seems
infeasible - the best I've got is examining DISPLAY, but where do you
draw the line between :0.0 or localhost:0 (probably local), foobar:0
(probably remote), and :10 (probably remote via ssh forwarding)? I'd
rather not try.

-- 
Scott Lamb <http://www.slamb.org/>

```

## Theodore Tso, 2007-06-18 13:18

Subject: Re: [PATCH] mergetool: make Apple's FileMerge available as a merge_tool
Message-ID: <20070618131800.GA30244@thunk.org>
URL: https://gitlist.dev/e/20070618131800.GA30244%40thunk.org
In-Reply-To: <467652BC.4050900@slamb.org>

```
On Mon, Jun 18, 2007 at 02:39:08AM -0700, Scott Lamb wrote:
> I propose a simpler test:
> 
>     if [ -n "$TERM_PROGRAM" ]; then
>         echo local
>     else
>         echo remote
>     fi
> 
> This environment variable seems to be set by Terminal.app and even two
> alternatives I just tried (iTerm.app and GLterm.app). It's not
> transmitted across ssh unless you stick an AcceptEnv in sshd_config.

Thanks, that's just what I was looking for!

						- Ted

```
