From ec245ba04944473ba6657a826643ef90ed02b51d Mon Sep 17 00:00:00 2001 From: David Aguilar Date: Thu, 19 Jan 2012 23:47:35 -0800 Subject: 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 Signed-off-by: David Aguilar Signed-off-by: Junio C Hamano --- git-mergetool.sh | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'git-mergetool.sh') diff --git a/git-mergetool.sh b/git-mergetool.sh index 085e213a1..a9f23f7fc 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':" -- cgit v1.2.1