Re: [PATCHv3] parse-remote: handle detached HEAD

2 messages, 2 authors, 2016-06-15 · open the first message on its own page

Re: [PATCHv3] parse-remote: handle detached HEAD

From: Junio C Hamano <hidden>
Date: 2016-06-15 22:50:11

Santi Béjar [off-list ref] writes:
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 <redacted>
Signed-off-by: Santi Béjar <redacted>
---
quoted
If that is the case, shouldn't we be not calling "echo" at all to begin
with?  IOW, shouldn't the code read more like this?

       curr_branch=$(git symbolic-ref -q HEAD) &&
       test "$origin" = "$default" &&
       echo ...
Or course, you are right. I didn't know/think about the exit
code... Thanks.
The calling codepath in git-pull that wants to determine remoteref and
oldremoteref seems to expect get-remote-merge-branch to succeed in order
to find its $oldremoteref variable, and returning false in detached HEAD
case here will change what happens there---it won't run "rev-list -g"
anymore and quits the codepath early, leaving the variable empty.

But we do want to set the variable to an empty string in this case anyway,
so there is no harm done (it probably is what we actually want to happen).

So this should be Ok.  Sverre, do you want to do another round of testing
just to be sure before I apply this?
quoted hunk
Santi

 git-parse-remote.sh |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/git-parse-remote.sh b/git-parse-remote.sh
index 5f47b18..4da72ae 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)
 	    ;;
-- 
1.7.3.3.399.g0d2be.dirty

Re: [PATCHv3] parse-remote: handle detached HEAD

From: Sverre Rabbelier <hidden>
Date: 2016-06-15 22:50:11

Heya,

On Mon, Dec 6, 2010 at 17:03, Junio C Hamano [off-list ref] wrote:
So this should be Ok.  Sverre, do you want to do another round of testing
just to be sure before I apply this?
Yup:

Tested-by: Sverre Rabbelier <srabbelier@gmail.com

-- 
Cheers,

Sverre Rabbelier
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help