# mergetool local/remote improvements?

1 messages from 2008-02-20 to 2008-02-20. Participants: Jay Soffian.
Thread: https://gitlist.dev/t/12221

## Jay Soffian, 2008-02-20 21:40

Subject: mergetool local/remote improvements?
Message-ID: <76718490802201340g5ce15c1fl3e4f6d4e655c96be@mail.gmail.com>
URL: https://gitlist.dev/e/76718490802201340g5ce15c1fl3e4f6d4e655c96be%40mail.gmail.com

```
When in branch <mine> and doing "git rebase <upstream>", if there are
any conflicts, the merge tool will come up with the version of the file
from branch <mine> tagged with ".REMOTE" and the version from branch
<upstream> tagged ".LOCAL".

I understand the reason for this, but still, it seems backwards. So I
was going to propose something like the patch below, but I realized that
it might be more useful if mergetool took --local and --remote arguments
so that the caller could provide more meaningful names, e.g. given

--local=mybranch
--remote=theirbranch

mergetool would use mybranch/MYBRANCH in place of local/LOCAL and
similarly theirbranch/THEIRBRANCH in place of remote/REMOTE.

Of course, I then have to wonder if mergetool could use branch names by
default in those cases where branch names can be determined
unambiguously (not sure how to do that though other than for git-merge
and git-rebase to leave a hint about the operation in progress).

Thoughts?

 git-mergetool.sh |   21 ++++++++++++++++-----
 1 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/git-mergetool.sh b/git-mergetool.sh
index cbbb707..c688858 100755
--- a/git-mergetool.sh
+++ b/git-mergetool.sh
@@ -20,6 +20,10 @@ is_symlink () {
     test "$1" = 120000
 }

+is_rebase_merge () {
+    test -d "$GIT_DIR/.dotest-merge"
+}
+
 local_present () {
     test -n "$local_mode"
 }
@@ -162,12 +166,19 @@ merge_file () {
     cp -- "$BACKUP" "$path"

     base_mode=`git ls-files -u -- "$path" | awk '{if ($3==1) print $1;}'`
-    local_mode=`git ls-files -u -- "$path" | awk '{if ($3==2) print $1;}'`
-    remote_mode=`git ls-files -u -- "$path" | awk '{if ($3==3) print $1;}'`
+    base_present && git cat-file blob ":1:$prefix$path" >"$BASE" 2>/dev/null

-    base_present   && git cat-file blob ":1:$prefix$path" >"$BASE" 2>/dev/null
-    local_present  && git cat-file blob ":2:$prefix$path" >"$LOCAL" 2>/dev/null
-    remote_present && git cat-file blob ":3:$prefix$path" >"$REMOTE"
2>/dev/null
+    if is_rebase_merge; then
+	local_mode=`git ls-files -u -- "$path" | awk '{if ($3==3) print $1;}'`
+	local_present  && git cat-file blob ":3:$prefix$path" >"$LOCAL" 2>/dev/null
+	remote_mode=`git ls-files -u -- "$path" | awk '{if ($3==2) print $1;}'`
+	remote_present && git cat-file blob ":2:$prefix$path" >"$REMOTE" 2>/dev/null
+    else
+	local_mode=`git ls-files -u -- "$path" | awk '{if ($3==2) print $1;}'`
+	local_present  && git cat-file blob ":2:$prefix$path" >"$LOCAL" 2>/dev/null
+	remote_mode=`git ls-files -u -- "$path" | awk '{if ($3==3) print $1;}'`
+	remote_present && git cat-file blob ":3:$prefix$path" >"$REMOTE" 2>/dev/null
+    fi

     if test -z "$local_mode" -o -z "$remote_mode"; then
 	echo "Deleted merge conflict for '$path':"

```
