Santi Béjar [off-list ref] 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 ...
quoted hunk
Reported-by: Sverre Rabbelier <redacted>
Signed-off-by: Santi Béjar <redacted>
Tested-by: Sverre Rabbelier <redacted>
---
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
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>
---
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
On Mon, Dec 6, 2010 at 11:20 AM, Santi Béjar [off-list ref] 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 <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.
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 <redacted>
Santi