Code

parse-remote: handle detached HEAD
authorSanti Béjar <santi@agolina.net>
Mon, 6 Dec 2010 10:20:11 +0000 (11:20 +0100)
committerJunio C Hamano <gitster@pobox.com>
Tue, 7 Dec 2010 00:57:48 +0000 (16:57 -0800)
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 <srabbelier@gmail.com>
Signed-off-by: Santi Béjar <santi@agolina.net>
Tested-by: Sverre Rabbelier <srabbelier@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
git-parse-remote.sh

index 5f47b18141a0758c3d0dae2cfe764495c92139c5..4da72aefbd226f6f42af381b5d5a5a3178414576 100644 (file)
@@ -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)
            ;;