{"thread":{"id":"12221","subject":"mergetool local/remote improvements?","startedAt":"2008-02-20T21:40:04Z","lastAt":"2008-02-20T21:40:04Z","messageCount":1,"participants":["Jay Soffian"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"69404","messageId":"76718490802201340g5ce15c1fl3e4f6d4e655c96be@mail.gmail.com","threadId":"12221","inReplyTo":null,"subject":"mergetool local/remote improvements?","fromName":"Jay Soffian","fromEmail":"jaysoffian@gmail.com","sentAt":"2008-02-20T21:40:04Z","receivedAt":"2008-02-20T21:40:04Z","isPatch":false,"sender":{"key":"jaysoffian@gmail.com","avatar":"https://avatars.githubusercontent.com/u/155970?v=4"},"body":"When in branch <mine> and doing \"git rebase <upstream>\", if there are\nany conflicts, the merge tool will come up with the version of the file\nfrom branch <mine> tagged with \".REMOTE\" and the version from branch\n<upstream> tagged \".LOCAL\".\n\nI understand the reason for this, but still, it seems backwards. So I\nwas going to propose something like the patch below, but I realized that\nit might be more useful if mergetool took --local and --remote arguments\nso that the caller could provide more meaningful names, e.g. given\n\n--local=mybranch\n--remote=theirbranch\n\nmergetool would use mybranch/MYBRANCH in place of local/LOCAL and\nsimilarly theirbranch/THEIRBRANCH in place of remote/REMOTE.\n\nOf course, I then have to wonder if mergetool could use branch names by\ndefault in those cases where branch names can be determined\nunambiguously (not sure how to do that though other than for git-merge\nand git-rebase to leave a hint about the operation in progress).\n\nThoughts?\n\n git-mergetool.sh |   21 ++++++++++++++++-----\n 1 files changed, 16 insertions(+), 5 deletions(-)\n\ndiff --git a/git-mergetool.sh b/git-mergetool.sh\nindex cbbb707..c688858 100755\n--- a/git-mergetool.sh\n+++ b/git-mergetool.sh\n@@ -20,6 +20,10 @@ is_symlink () {\n     test \"$1\" = 120000\n }\n\n+is_rebase_merge () {\n+    test -d \"$GIT_DIR/.dotest-merge\"\n+}\n+\n local_present () {\n     test -n \"$local_mode\"\n }\n@@ -162,12 +166,19 @@ merge_file () {\n     cp -- \"$BACKUP\" \"$path\"\n\n     base_mode=`git ls-files -u -- \"$path\" | awk '{if ($3==1) print $1;}'`\n-    local_mode=`git ls-files -u -- \"$path\" | awk '{if ($3==2) print $1;}'`\n-    remote_mode=`git ls-files -u -- \"$path\" | awk '{if ($3==3) print $1;}'`\n+    base_present && git cat-file blob \":1:$prefix$path\" >\"$BASE\" 2>/dev/null\n\n-    base_present   && git cat-file blob \":1:$prefix$path\" >\"$BASE\" 2>/dev/null\n-    local_present  && git cat-file blob \":2:$prefix$path\" >\"$LOCAL\" 2>/dev/null\n-    remote_present && git cat-file blob \":3:$prefix$path\" >\"$REMOTE\"\n2>/dev/null\n+    if is_rebase_merge; then\n+\tlocal_mode=`git ls-files -u -- \"$path\" | awk '{if ($3==3) print $1;}'`\n+\tlocal_present  && git cat-file blob \":3:$prefix$path\" >\"$LOCAL\" 2>/dev/null\n+\tremote_mode=`git ls-files -u -- \"$path\" | awk '{if ($3==2) print $1;}'`\n+\tremote_present && git cat-file blob \":2:$prefix$path\" >\"$REMOTE\" 2>/dev/null\n+    else\n+\tlocal_mode=`git ls-files -u -- \"$path\" | awk '{if ($3==2) print $1;}'`\n+\tlocal_present  && git cat-file blob \":2:$prefix$path\" >\"$LOCAL\" 2>/dev/null\n+\tremote_mode=`git ls-files -u -- \"$path\" | awk '{if ($3==3) print $1;}'`\n+\tremote_present && git cat-file blob \":3:$prefix$path\" >\"$REMOTE\" 2>/dev/null\n+    fi\n\n     if test -z \"$local_mode\" -o -z \"$remote_mode\"; then\n \techo \"Deleted merge conflict for '$path':\"\n"}]}