summary refs log tree commit diff
path: root/git-mergetool.sh
diff options
context:
space:
mode:
authorDavid Aguilar <davvid@gmail.com>2012-01-19 23:47:35 -0800
committerJunio C Hamano <gitster@pobox.com>2012-01-23 11:50:22 -0800
commitec245ba04944473ba6657a826643ef90ed02b51d (patch)
treea2efa5abe53ebc42761cad8a8b58a513083f36e6 /git-mergetool.sh
parent5fbdb9c2e8cc7226d9a9e7de5ad09ac5f0a0b906 (diff)
mergetool: Provide an empty file when needed
Some merge tools cannot cope when $LOCAL, $BASE, or $REMOTE are missing.
$BASE can be missing when two branches independently add the same
filename.

Provide an empty file to make these tools happy.

When a delete/modify conflict occurs, $LOCAL and $REMOTE can also be
missing. We have special case code to handle such case so this change
may not affect that codepath, but try to be consistent and create an
empty file for them anyway.

Reported-by: Jason Wenger <jcwenger@gmail.com>
Signed-off-by: David Aguilar <davvid@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'git-mergetool.sh')
-rwxr-xr-xgit-mergetool.sh12
1 files changed, 8 insertions, 4 deletions
diff --git a/git-mergetool.sh b/git-mergetool.sh
index 085e213a12..a9f23f7fcd 100755
--- a/git-mergetool.sh
+++ b/git-mergetool.sh
@@ -181,10 +181,14 @@ stage_submodule () {
 }
 
 checkout_staged_file () {
-    tmpfile=$(expr "$(git checkout-index --temp --stage="$1" "$2")" : '\([^	]*\)	')
+    tmpfile=$(expr \
+	    "$(git checkout-index --temp --stage="$1" "$2" 2>/dev/null)" \
+	    : '\([^	]*\)	')
 
     if test $? -eq 0 -a -n "$tmpfile" ; then
 	mv -- "$(git rev-parse --show-cdup)$tmpfile" "$3"
+    else
+	>"$3"
     fi
 }
 
@@ -224,9 +228,9 @@ merge_file () {
     mv -- "$MERGED" "$BACKUP"
     cp -- "$BACKUP" "$MERGED"
 
-    base_present   && checkout_staged_file 1 "$MERGED" "$BASE"
-    local_present  && checkout_staged_file 2 "$MERGED" "$LOCAL"
-    remote_present && checkout_staged_file 3 "$MERGED" "$REMOTE"
+    checkout_staged_file 1 "$MERGED" "$BASE"
+    checkout_staged_file 2 "$MERGED" "$LOCAL"
+    checkout_staged_file 3 "$MERGED" "$REMOTE"
 
     if test -z "$local_mode" -o -z "$remote_mode"; then
 	echo "Deleted merge conflict for '$MERGED':"