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

minor bug in git pull --rebase

From
Phil Hord <phil.hord@gmail.com>
Date
Oct 12, 2012, 22:47 UTC
Message-ID
<CABURp0rxUY9Tj3x3AM7avAg5FXDZXovo-9SZDF5OJ+kxB+nsnQ@mail.gmail.com>

I saw some unexpected usage output today in git pull --rebase when I was on a detached head.

$ git pull --rebase origin BL/3.0
usage: git merge-base [-a|--all] <commit> <commit>...
   or: git merge-base [-a|--all] --octopus <commit>...
   or: git merge-base --independent <commit>...
   or: git merge-base --is-ancestor <commit> <commit>
    -a, --all             output all common ancestors
    --octopus             find ancestors for a single n-way merge
    --independent         list revs not reachable from others
    --is-ancestor         is the first one ancestor of the other?
>From gerrit:iptv/bootloader-all
 * branch            BL/3.0     -> FETCH_HEAD
First, rewinding head to replay your work on top of it...
Fast-forwarded HEAD to 99ba23a9fce5c5becb9dd86b5f76a8467286d811.
$

It occurs when using pull --rebase on a detached head. It's because git-pull doesn't expect ${current_branch} to be empty in some places, but it does check in others. It appears to have been introduced three years ago and no one seems to have complained yet. I hesitate to mention it during a release cycle, but I worry I'll forget later.

Here's a patch.
-- >8 --
Subject: [PATCH] git-pull: Avoid merge-base on detached head

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. As a result, git merge-base emits some usage noise in the middle of an otherwise successful rebase operation.

Since we do not need the merge-base trick in the case of a
detached HEAD, detect this condition and bypass the clever
trick.
---
There is another git-merge-base call which may need similar
treatment, but I have not dug deeply enough to see for sure.
 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.rc2.1.g44028c0.dirty

Phil
Message 1 of 1 in “minor bug in git pull --rebase”
  1. Phil HordOct 12, 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.