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

[PATCHv2] git-pull: Avoid merge-base on detached head

From
Phil Hord <hordp@cisco.com>
Date
Oct 23, 2012, 20:39 UTC
Message-ID
<1351024796-28174-2-git-send-email-hordp@cisco.com>
In-Reply-To
<1351024796-28174-1-git-send-email-hordp@cisco.com>

git pull --rebase does some clever tricks to find the base for $upstream , but it forgets that we may not have any branch at all. When this happens, git merge-base reports its "usage" help in the middle of an otherwise successful rebase operation, because git-merge is called with one too few parameters.

Since we do not need the merge-base trick in the case of a detached HEAD, detect this condition and bypass the clever trick and the usage noise.

Signed-off-by: Phil Hord <hordp@cisco.com>
---
 git-pull.sh | 1 +
 1 file changed, 1 insertion(+)
diff --git a/git-pull.sh b/git-pull.sh
index 2a10047..266e682 100755
--- a/git-pull.sh
+++ b/git-pull.sh
@@ -200,6 +200,7 @@ test true = "$rebase" && {
 		require_clean_work_tree "pull with rebase" "Please commit or stash them."
 	fi
 	oldremoteref= &&
+	test -n "$curr_branch" &&
 	. git-parse-remote &&
 	remoteref="$(get_remote_merge_branch "$@" 2>/dev/null)" &&
 	oldremoteref="$(git rev-parse -q --verify "$remoteref")" &&
-- 
1.8.0.2.gc921d59.dirty
Previous: Phil HordNext: Jeff King
Message 2 of 5 in “[PATCHv2] git-pull: Avoid merge-base on detached head”
  1. Phil HordOct 23, 2012
  2. Phil HordOct 23, 2012
  3. Jeff KingOct 25, 2012
  4. Phil HordOct 25, 2012
  5. Jeff KingOct 26, 2012

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.