All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] parse-remote: handle detached HEAD
@ 2010-12-05 23:47 Santi Béjar
  2010-12-05 23:49 ` Sverre Rabbelier
  0 siblings, 1 reply; 8+ messages in thread
From: Santi Béjar @ 2010-12-05 23:47 UTC (permalink / raw)
  To: git; +Cc: Sverre Rabbelier

In get_remote_merge_branch 'git for-each-ref' is used to know the
upstream branch of the current branch ($curr_branch). But $curr_branch
can be empty when in detached HEAD, so the call to for-each-ref is
made without a pattern.

Quote the $curr_branch variable in the git for-each-ref call to always
provide a pattern (the current branch or an empty string) Otherwise it
would mean all refs.

This fixes a bug reported by Sverre Rabbelier. The overall results
were correct but not the output text.

Signed-off-by: Santi Béjar <santi@agolina.net>
---
Hi *,

Sorry Sverre, but the patch you tested fixed your case but broke all
the others :(

Hope you can also test it. Now it passes the test suite.

Thanks,
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..07060c3 100644
--- a/git-parse-remote.sh
+++ b/git-parse-remote.sh
@@ -68,7 +68,7 @@ get_remote_merge_branch () {
 	    test -z "$origin" && origin=$default
 	    curr_branch=$(git symbolic-ref -q HEAD)
 	    [ "$origin" = "$default" ] &&
-	    echo $(git for-each-ref --format='%(upstream)' $curr_branch)
+	    echo $(git for-each-ref --format='%(upstream)' "$curr_branch")
 	    ;;
 	*)
 	    repo=$1
-- 
1.7.3.3.399.gea47f

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH] parse-remote: handle detached HEAD
  2010-12-05 23:47 [PATCH] parse-remote: handle detached HEAD Santi Béjar
@ 2010-12-05 23:49 ` Sverre Rabbelier
  2010-12-05 23:58   ` [PATCHv2] " Santi Béjar
  0 siblings, 1 reply; 8+ messages in thread
From: Sverre Rabbelier @ 2010-12-05 23:49 UTC (permalink / raw)
  To: Santi Béjar; +Cc: git

Heya,

On Mon, Dec 6, 2010 at 00:47, Santi Béjar <santi@agolina.net> wrote:
> This fixes a bug reported by Sverre Rabbelier. The overall results
> were correct but not the output text.

I think we usually use:

Reported-by: Sverre Rabbelier <srabbelier@gmail.com>

But since I already verified the fix, perhaps just:

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

is enough? Both are fine with me.

-- 
Cheers,

Sverre Rabbelier

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCHv2] parse-remote: handle detached HEAD
  2010-12-05 23:49 ` Sverre Rabbelier
@ 2010-12-05 23:58   ` Santi Béjar
  2010-12-06  3:33     ` Junio C Hamano
  0 siblings, 1 reply; 8+ messages in thread
From: Santi Béjar @ 2010-12-05 23:58 UTC (permalink / raw)
  To: git; +Cc: Sverre Rabbelier, Junio C Hamano

In get_remote_merge_branch 'git for-each-ref' is used to know the
upstream branch of the current branch ($curr_branch). But $curr_branch
can be empty when in detached HEAD, so the call to for-each-ref is
made without a pattern.

Quote the $curr_branch variable in the git for-each-ref call to always
provide a pattern (the current branch or an empty string) Otherwise it
would mean all refs.

Reported-by: Sverre Rabbelier <srabbelier@gmail.com>
Signed-off-by: Santi Béjar <santi@agolina.net>
Tested-by: Sverre Rabbelier <srabbelier@gmail.com>
---
Changes since v1:
  Tags for Reported-by and Tested-by.

 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..07060c3 100644
--- a/git-parse-remote.sh
+++ b/git-parse-remote.sh
@@ -68,7 +68,7 @@ get_remote_merge_branch () {
 	    test -z "$origin" && origin=$default
 	    curr_branch=$(git symbolic-ref -q HEAD)
 	    [ "$origin" = "$default" ] &&
-	    echo $(git for-each-ref --format='%(upstream)' $curr_branch)
+	    echo $(git for-each-ref --format='%(upstream)' "$curr_branch")
 	    ;;
 	*)
 	    repo=$1
-- 
1.7.3.3.399.gea47f

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCHv2] parse-remote: handle detached HEAD
  2010-12-05 23:58   ` [PATCHv2] " Santi Béjar
@ 2010-12-06  3:33     ` Junio C Hamano
  2010-12-06 10:20       ` [PATCHv3] " Santi Béjar
  0 siblings, 1 reply; 8+ messages in thread
From: Junio C Hamano @ 2010-12-06  3:33 UTC (permalink / raw)
  To: Santi Béjar; +Cc: git, Sverre Rabbelier

Santi Béjar <santi@agolina.net> writes:

> In get_remote_merge_branch 'git for-each-ref' is used to know the
> upstream branch of the current branch ($curr_branch). But $curr_branch
> can be empty when in detached HEAD, so the call to for-each-ref is
> made without a pattern.
>
> Quote the $curr_branch variable in the git for-each-ref call to always
> provide a pattern (the current branch or an empty string) Otherwise it
> would mean all refs.

What output do you want to see in this case?  "Nothing needs to be
reported because on detached head you are not tracking anything?"

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 ...

> Reported-by: Sverre Rabbelier <srabbelier@gmail.com>
> Signed-off-by: Santi Béjar <santi@agolina.net>
> Tested-by: Sverre Rabbelier <srabbelier@gmail.com>
> ---
> Changes since v1:
>   Tags for Reported-by and Tested-by.
>
>  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..07060c3 100644
> --- a/git-parse-remote.sh
> +++ b/git-parse-remote.sh
> @@ -68,7 +68,7 @@ get_remote_merge_branch () {
>  	    test -z "$origin" && origin=$default
>  	    curr_branch=$(git symbolic-ref -q HEAD)
>  	    [ "$origin" = "$default" ] &&
> -	    echo $(git for-each-ref --format='%(upstream)' $curr_branch)
> +	    echo $(git for-each-ref --format='%(upstream)' "$curr_branch")
>  	    ;;
>  	*)
>  	    repo=$1

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCHv3] parse-remote: handle detached HEAD
  2010-12-06  3:33     ` Junio C Hamano
@ 2010-12-06 10:20       ` Santi Béjar
  2010-12-06 14:32         ` Santi Béjar
  2010-12-06 16:03         ` Junio C Hamano
  0 siblings, 2 replies; 8+ messages in thread
From: Santi Béjar @ 2010-12-06 10:20 UTC (permalink / raw)
  To: git; +Cc: Sverre Rabbelier, Junio C Hamano

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>
---

> 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.

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

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCHv3] parse-remote: handle detached HEAD
  2010-12-06 10:20       ` [PATCHv3] " Santi Béjar
@ 2010-12-06 14:32         ` Santi Béjar
  2010-12-06 16:03         ` Junio C Hamano
  1 sibling, 0 replies; 8+ messages in thread
From: Santi Béjar @ 2010-12-06 14:32 UTC (permalink / raw)
  To: git; +Cc: Sverre Rabbelier, Junio C Hamano

On Mon, Dec 6, 2010 at 11:20 AM, Santi Béjar <santi@agolina.net> wrote:
> 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>
> ---
>
>> 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.

Now that I think of... the final form of the patch is yours (Junio).
Feel free to add something like this to the commit message:

Final patch form by Junio C Hamano

Or alternatively, take ownership of the patch and add something like
"Patch handled by Santi Béjar but final patch form by Junio C Hamano"
and:

Acked-by: Santi Béjar <santi@agolina.net>

Santi

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCHv3] parse-remote: handle detached HEAD
  2010-12-06 10:20       ` [PATCHv3] " Santi Béjar
  2010-12-06 14:32         ` Santi Béjar
@ 2010-12-06 16:03         ` Junio C Hamano
  2010-12-06 17:14           ` Sverre Rabbelier
  1 sibling, 1 reply; 8+ messages in thread
From: Junio C Hamano @ 2010-12-06 16:03 UTC (permalink / raw)
  To: Santi Béjar; +Cc: git, Sverre Rabbelier

Santi Béjar <santi@agolina.net> 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 <srabbelier@gmail.com>
> Signed-off-by: Santi Béjar <santi@agolina.net>
> ---
>
>> 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?

> 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

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCHv3] parse-remote: handle detached HEAD
  2010-12-06 16:03         ` Junio C Hamano
@ 2010-12-06 17:14           ` Sverre Rabbelier
  0 siblings, 0 replies; 8+ messages in thread
From: Sverre Rabbelier @ 2010-12-06 17:14 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Santi Béjar, git

Heya,

On Mon, Dec 6, 2010 at 17:03, Junio C Hamano <gitster@pobox.com> 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

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2010-12-06 17:15 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-12-05 23:47 [PATCH] parse-remote: handle detached HEAD Santi Béjar
2010-12-05 23:49 ` Sverre Rabbelier
2010-12-05 23:58   ` [PATCHv2] " Santi Béjar
2010-12-06  3:33     ` Junio C Hamano
2010-12-06 10:20       ` [PATCHv3] " Santi Béjar
2010-12-06 14:32         ` Santi Béjar
2010-12-06 16:03         ` Junio C Hamano
2010-12-06 17:14           ` Sverre Rabbelier

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.