# BUG: git pull --rebase on detatched head prints a lot of usage warnings

8 messages from 2010-12-03 to 2010-12-03. Participants: Sverre Rabbelier, Jonathan Nieder, Santi Béjar, Junio C Hamano.
Thread: https://gitlist.dev/t/25941

## Sverre Rabbelier, 2010-12-03 18:38

Subject: BUG: git pull --rebase on detatched head prints a lot of usage warnings
Message-ID: <AANLkTimyCG6zVhc4znWPWwipd0bn-YT2FrOT=T0AgHNW@mail.gmail.com>
URL: https://gitlist.dev/e/AANLkTimyCG6zVhc4znWPWwipd0bn-YT2FrOT%3DT0AgHNW%40mail.gmail.com

```
Heya,

sverre@laptop-sverre:~/code/Melange
$ git pull --rebase
usage: git merge-base [-a|--all] [--octopus] <commit> <commit>...
   or: git merge-base --independent <commit>...

    -a, --all             output all common ancestors
    --octopus             find ancestors for a single n-way merge
    --independent         list revs not reachable from others

usage: git merge-base [-a|--all] [--octopus] <commit> <commit>...
   or: git merge-base --independent <commit>...

    -a, --all             output all common ancestors
    --octopus             find ancestors for a single n-way merge
    --independent         list revs not reachable from others

usage: git merge-base [-a|--all] [--octopus] <commit> <commit>...
   or: git merge-base --independent <commit>...

    -a, --all             output all common ancestors
    --octopus             find ancestors for a single n-way merge
    --independent         list revs not reachable from others


[... many more snipped ...]

You are not currently on a branch, so I cannot use any
'branch.<branchname>.merge' in your configuration file.
Please specify which remote branch you want to use on the command
line and try again (e.g. 'git pull <repository> <refspec>').
See git-pull(1) for details.


There are 127 helpful messages in total.

Output with GIT_TRACE set:

trace: exec: 'git-pull' '--rebase'
trace: run_command: 'git-pull' '--rebase'
trace: built-in: git 'rev-parse' '--git-dir'
trace: built-in: git 'rev-parse' '--is-inside-work-tree'
trace: built-in: git 'rev-parse' '--show-toplevel'
trace: built-in: git 'ls-files' '-u'
trace: built-in: git 'symbolic-ref' '-q' 'HEAD'
trace: built-in: git 'config' '--bool' 'branch..rebase'
trace: built-in: git 'rev-parse' '-q' '--verify' 'HEAD'
trace: built-in: git 'rev-parse' '--verify' 'HEAD'
trace: built-in: git 'update-index' '-q' '--ignore-submodules' '--refresh'
trace: built-in: git 'diff-files' '--quiet' '--ignore-submodules'
trace: built-in: git 'diff-index' '--cached' '--quiet'
'--ignore-submodules' 'HEAD' '--'
trace: built-in: git 'rev-parse' '-q' '--git-dir'
trace: built-in: git 'symbolic-ref' '-q' 'HEAD'
trace: built-in: git 'config' '--get' 'branch..remote'
trace: built-in: git 'symbolic-ref' '-q' 'HEAD'
trace: built-in: git 'for-each-ref' '--format=%(upstream)'
trace: built-in: git 'rev-parse' '-q' '--verify' 'refs/remotes/origin/tip'
trace: built-in: git 'rev-list' '-g' 'refs/remotes/origin/tip'
trace: built-in: git 'merge-base' '927b640697cf707a8d3d26b39c926be052c3aa7c'
trace: built-in: git 'merge-base' '8281385d7b5132a51ae1f3ad515f0220478c7f40'

Tested on current next.

-- 
Cheers,

Sverre Rabbelier

```

## Jonathan Nieder, 2010-12-03 19:00

Subject: Re: BUG: git pull --rebase on detatched head prints a lot of usage warnings
Message-ID: <20101203190050.GB14049@burratino>
URL: https://gitlist.dev/e/20101203190050.GB14049%40burratino
In-Reply-To: <AANLkTimyCG6zVhc4znWPWwipd0bn-YT2FrOT=T0AgHNW@mail.gmail.com>

```
Sverre Rabbelier wrote:

> $ git pull --rebase
> usage: git merge-base [-a|--all] [--octopus] <commit> <commit>...
[...]
> [... many more snipped ...]
>
> You are not currently on a branch, so I cannot use any
> 'branch.<branchname>.merge' in your configuration file.
> Please specify which remote branch you want to use on the command
> line and try again (e.g. 'git pull <repository> <refspec>').
> See git-pull(1) for details.
>
>
> There are 127 helpful messages in total.

Does the following take care of it?

cc-ing Santi, author of the very nice v1.6.4.1~6^2 (pull: support
rebased upstream + fetch + pull --rebase, 2009-07-19).  Maybe we
should make merge-base more tolerant.

diff --git a/git-pull.sh b/git-pull.sh
index 8eb74d4..bbc369d 100755
--- a/git-pull.sh
+++ b/git-pull.sh
@@ -212,7 +212,7 @@ test true = "$rebase" && {
 	oldremoteref="$(git rev-parse -q --verify "$remoteref")" &&
 	for reflog in $(git rev-list -g $remoteref 2>/dev/null)
 	do
-		if test "$reflog" = "$(git merge-base $reflog $curr_branch)"
+		if test "$reflog" = "$(git show-branch --merge-base $reflog $curr_branch)"
 		then
 			oldremoteref="$reflog"
 			break

```

## Sverre Rabbelier, 2010-12-03 19:05

Subject: Re: BUG: git pull --rebase on detatched head prints a lot of usage warnings
Message-ID: <AANLkTin-9pb7cxsAvDqWj3So47_zq5co9TZRWux9ezxz@mail.gmail.com>
URL: https://gitlist.dev/e/AANLkTin-9pb7cxsAvDqWj3So47_zq5co9TZRWux9ezxz%40mail.gmail.com
In-Reply-To: <20101203190050.GB14049@burratino>

```
Heya,

On Fri, Dec 3, 2010 at 20:00, Jonathan Nieder <jrnieder@gmail.com> wrote:
> Does the following take care of it?

Yes.

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

-- 
Cheers,

Sverre Rabbelier

```

## Santi Béjar, 2010-12-03 20:23

Subject: Re: BUG: git pull --rebase on detatched head prints a lot of usage warnings
Message-ID: <AANLkTikwdqQpmyxZu-kp7UHjYnKuVxs8urxM=9c=66H0@mail.gmail.com>
URL: https://gitlist.dev/e/AANLkTikwdqQpmyxZu-kp7UHjYnKuVxs8urxM%3D9c%3D66H0%40mail.gmail.com
In-Reply-To: <AANLkTin-9pb7cxsAvDqWj3So47_zq5co9TZRWux9ezxz@mail.gmail.com>

```
On Fri, Dec 3, 2010 at 8:05 PM, Sverre Rabbelier <srabbelier@gmail.com> wrote:
> Heya,
>
> On Fri, Dec 3, 2010 at 20:00, Jonathan Nieder <jrnieder@gmail.com> wrote:
>> Does the following take care of it?
>
> Yes.

I also think it fixes, but I wonder if it's the best fix. One thing is
that show-branch is an ancillary command, and not a plumbing command
(but there is already a call to show-branch, but it should probably be
change to merge-base now that it handles three commit as arguments).

The problem is that many parts of git-pull.sh/git-parse-remote.sh
assume that you are not in a detached HEAD. Can you confirm that the
following patch fixes it?

diff --git i/git-parse-remote.sh w/git-parse-remote.sh
index 5f47b18..6d0a5de 100644
--- i/git-parse-remote.sh
+++ w/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)' HEAD)
            ;;
        *)
            repo=$1

I'm wondering if most of $curr_branch should be changed to HEAD, I'll check it.

HTH,
Santi

```

## Sverre Rabbelier, 2010-12-03 20:45

Subject: Re: BUG: git pull --rebase on detatched head prints a lot of usage warnings
Message-ID: <AANLkTikNLqBo+5JnVSRhpdC9qWJHggmo02-xDCxmmZKG@mail.gmail.com>
URL: https://gitlist.dev/e/AANLkTikNLqBo%2B5JnVSRhpdC9qWJHggmo02-xDCxmmZKG%40mail.gmail.com
In-Reply-To: <AANLkTikwdqQpmyxZu-kp7UHjYnKuVxs8urxM=9c=66H0@mail.gmail.com>

```
Heya,

On Fri, Dec 3, 2010 at 21:23, Santi Béjar <santi@agolina.net> wrote:
> The problem is that many parts of git-pull.sh/git-parse-remote.sh
> assume that you are not in a detached HEAD. Can you confirm that the
> following patch fixes it?

Yes.

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

-- 
Cheers,

Sverre Rabbelier

```

## Junio C Hamano, 2010-12-03 21:06

Subject: Re: BUG: git pull --rebase on detatched head prints a lot of usage warnings
Message-ID: <7vbp52o9c6.fsf@alter.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vbp52o9c6.fsf%40alter.siamese.dyndns.org
In-Reply-To: <AANLkTikwdqQpmyxZu-kp7UHjYnKuVxs8urxM=9c=66H0@mail.gmail.com>

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

> I also think it fixes, but I wonder if it's the best fix. One thing is
> that show-branch is an ancillary command, and not a plumbing command
> (but there is already a call to show-branch, but it should probably be
> change to merge-base now that it handles three commit as arguments).

Are you sure "show-branch --merge-base A B C" and "merge-base A B C" are
meant to compute the same thing?

I do not think ancillary necessarily means Porcelain, but that is a
separate issue.

```

## Santi Béjar, 2010-12-03 22:16

Subject: Re: BUG: git pull --rebase on detatched head prints a lot of usage warnings
Message-ID: <AANLkTimgk-jqyKD+ab=bHZLVH3F52WqCjr4v3chMY_Fv@mail.gmail.com>
URL: https://gitlist.dev/e/AANLkTimgk-jqyKD%2Bab%3DbHZLVH3F52WqCjr4v3chMY_Fv%40mail.gmail.com
In-Reply-To: <7vbp52o9c6.fsf@alter.siamese.dyndns.org>

```
On Fri, Dec 3, 2010 at 10:06 PM, Junio C Hamano <gitster@pobox.com> wrote:
> Santi Béjar <santi@agolina.net> writes:
>
>> I also think it fixes, but I wonder if it's the best fix. One thing is
>> that show-branch is an ancillary command, and not a plumbing command
>> (but there is already a call to show-branch, but it should probably be
>> change to merge-base now that it handles three commit as arguments).
>
> Are you sure "show-branch --merge-base A B C" and "merge-base A B C" are
> meant to compute the same thing?

No, I'm not sure. In fact the documentation explicit says that they
are different. But I fail to see when it matters, and more
specifically (now that I've reread the docs), what is the point of
"merge-base A B C".

Just a data point, show-branch --merge-base is only used once in the
code, in git-pull.sh, but "git merge-base A B C" is not used (at least
using my grep).

Or the equivalent is the undocumented "git merge-base --octopus A B C"?

>
> I do not think ancillary necessarily means Porcelain, but that is a
> separate issue.

Me neither. But is the promise to not change the behavior/output as
hard as with plumbing?

Santi

```

## Junio C Hamano, 2010-12-03 22:31

Subject: Re: BUG: git pull --rebase on detatched head prints a lot of usage warnings
Message-ID: <7vy686lc82.fsf@alter.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vy686lc82.fsf%40alter.siamese.dyndns.org
In-Reply-To: <AANLkTimgk-jqyKD+ab=bHZLVH3F52WqCjr4v3chMY_Fv@mail.gmail.com>

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

> No, I'm not sure. In fact the documentation explicit says that they
> are different. But I fail to see when it matters, and more
> specifically (now that I've reread the docs), what is the point of
> "merge-base A B C".

See c5dc9a2 (git-merge-octopus: use (merge-base A (merge B C D E...)) for
stepwise merge, 2008-07-27), not the patch but the explanation.

> Just a data point, show-branch --merge-base is only used once in the
> code, in git-pull.sh, but "git merge-base A B C" is not used (at least
> using my grep).

Your grep skill needs honing ;-)  The variable MRC in git-merge-octopus is
a space separated list of commit object names, split at $IFS when
merge-base is called.

```
