From: Santi Béjar Date: Mon, 6 Dec 2010 10:20:11 +0000 (+0100) Subject: parse-remote: handle detached HEAD X-Git-Tag: v1.7.4-rc0~86 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=f864f2615b76e5d74518c482ceeef3a2589017fe;p=git.git parse-remote: handle detached HEAD get_remote_merge_branch with zero or one arguments returns the upstream branch. But a detached HEAD does no have an upstream branch, as it is not tracking anything. Handle this case testing the exit code of "git symbolic-ref -q HEAD". Reported-by: Sverre Rabbelier Signed-off-by: Santi Béjar Tested-by: Sverre Rabbelier Signed-off-by: Junio C Hamano --- diff --git a/git-parse-remote.sh b/git-parse-remote.sh index 5f47b1814..4da72aefb 100644 --- a/git-parse-remote.sh +++ b/git-parse-remote.sh @@ -66,7 +66,7 @@ get_remote_merge_branch () { origin="$1" default=$(get_default_remote) test -z "$origin" && origin=$default - curr_branch=$(git symbolic-ref -q HEAD) + curr_branch=$(git symbolic-ref -q HEAD) && [ "$origin" = "$default" ] && echo $(git for-each-ref --format='%(upstream)' $curr_branch) ;;