git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] git-{parse-remote,pull}: throw away stderr of git-symbolic-ref

From
Jeff King <peff@peff.net>
Date
Jan 15, 2007, 21:24 UTC
Message-ID
<20070115212442.GA7409@coredump.intra.peff.net>
In-Reply-To
<200701151009.51868.andyparkins@gmail.com>

We look up the destination of the HEAD symref in order to get the default remote and merge head for the current branch. However, if we have a detached HEAD, there is no current branch. We handle this situation by looking up branch..remote, which is empty. Unfortunately, git-symbolic-ref complained to stderr, potentially scaring users.

Signed-off-by: Jeff King <peff@peff.net>
---
 git-parse-remote.sh |    4 ++--
 git-pull.sh         |    2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/git-parse-remote.sh b/git-parse-remote.sh
index d2e4c2b..bc2485f 100755
--- a/git-parse-remote.sh
+++ b/git-parse-remote.sh
@@ -49,7 +49,7 @@ get_remote_url () {
 }
 
 get_default_remote () {
-	curr_branch=$(git-symbolic-ref HEAD | sed -e 's|^refs/heads/||')
+	curr_branch=$(git-symbolic-ref HEAD 2>/dev/null | sed -e 's|^refs/heads/||')
 	origin=$(git-repo-config --get "branch.$curr_branch.remote")
 	echo ${origin:-origin}
 }
@@ -137,7 +137,7 @@ canon_refs_list_for_fetch () {
 		shift
 		if test "$remote" = "$(get_default_remote)"
 		then
-			curr_branch=$(git-symbolic-ref HEAD | \
+			curr_branch=$(git-symbolic-ref HEAD 2>/dev/null | \
 			    sed -e 's|^refs/heads/||')
 			merge_branches=$(git-repo-config \
 			    --get-all "branch.${curr_branch}.merge")
diff --git a/git-pull.sh b/git-pull.sh
index 9592617..f0cc023 100755
--- a/git-pull.sh
+++ b/git-pull.sh
@@ -83,7 +83,7 @@ merge_head=$(sed -e '/	not-for-merge	/d' \
 
 case "$merge_head" in
 '')
-	curr_branch=$(git-symbolic-ref HEAD | \
+	curr_branch=$(git-symbolic-ref HEAD 2>/dev/null | \
 		sed -e 's|^refs/heads/||')
 	echo >&2 "Warning: No merge candidate found because value of config option
          \"branch.${curr_branch}.merge\" does not match any remote branch fetched."
-- 
1.5.0.rc1.gd61e-dirty
Previous: Andy ParkinsNext: Junio C Hamano
Message 2 of 7 in “git-fetch while on "(no branch)"”
  1. Andy ParkinsJan 15, 2007
  2. git-{parse-remote,pull}: throw away stderr of git-symbolic-refJeff King, Jan 15, 2007
  3. Junio C HamanoJan 15, 2007
  4. git-pull: disallow implicit merging to detached HEADJeff King, Jan 15, 2007
  5. Jeff KingJan 15, 2007
  6. Junio C HamanoJan 15, 2007
  7. Jeff KingJan 15, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.