# [PATCH 2/3] pull --rebase: Add support for rebased default upstream

3 messages from 2009-06-05 to 2009-06-06. Participants: Santi Béjar, Johannes Schindelin.
Thread: https://gitlist.dev/t/19702

## Santi Béjar, 2009-06-05 19:53

Subject: [PATCH 2/3] pull --rebase: Add support for rebased default upstream
Message-ID: <1244231617-17754-2-git-send-email-santi@agolina.net>
URL: https://gitlist.dev/e/1244231617-17754-2-git-send-email-santi%40agolina.net

```
Also add a test to check for this case and another one (failing) to
test rebasing two branches on top of a rebased upstream using just
'git pull --rebase'.

Signed-off-by: Santi Béjar <santi@agolina.net>
---
 git-parse-remote.sh |    8 +++++++-
 t/t5520-pull.sh     |   29 +++++++++++++++++++++++++++++
 2 files changed, 36 insertions(+), 1 deletions(-)

diff --git a/git-parse-remote.sh b/git-parse-remote.sh
index 8b3ba72..5df5689 100644
--- a/git-parse-remote.sh
+++ b/git-parse-remote.sh
@@ -232,7 +232,13 @@ get_remote_refs_for_fetch () {
 get_remote_merge_branch () {
 	case "$#" in
 	0|1)
-	    die "internal error: get-remote-merge-branch." ;;
+	    origin="$1"
+	    default=$(get_default_remote)
+	    test -z "$origin" && origin=$default
+	    curr_branch=$(git symbolic-ref -q HEAD)
+	    [ "$origin" = "$default" ] &&
+	    echo $(git for-each-ref --format='%(upstream)' $curr_branch)
+	    ;;
 	*)
 	    repo=$1
 	    shift
diff --git a/t/t5520-pull.sh b/t/t5520-pull.sh
index 725771f..359a3e2 100755
--- a/t/t5520-pull.sh
+++ b/t/t5520-pull.sh
@@ -92,20 +92,49 @@ test_expect_success '--rebase with rebased upstream' '
 
 	git remote add -f me . &&
 	git checkout copy &&
+	git tag copy-orig &&
 	git reset --hard HEAD^ &&
 	echo conflicting modification > file &&
 	git commit -m conflict file &&
 	git checkout to-rebase &&
 	echo file > file2 &&
 	git commit -m to-rebase file2 &&
+	git tag to-rebase-orig &&
 	git pull --rebase me copy &&
 	test "conflicting modification" = "$(cat file)" &&
 	test file = $(cat file2)
 
 '
 
+test_expect_success '--rebase with rebased default upstream' '
+
+	git update-ref refs/remotes/me/copy copy-orig &&
+	git checkout --track -b to-rebase2 me/copy &&
+	git reset --hard to-rebase-orig &&
+	git pull --rebase &&
+	test "conflicting modification" = "$(cat file)" &&
+	test file = $(cat file2)
+
+'
+
+test_expect_failure '--rebase with rebased upstream and two branches' '
+
+	git update-ref refs/remotes/me/copy copy-orig &&
+	git reset --hard to-rebase-orig &&
+	git checkout --track -b to-rebase3 me/copy &&
+	git reset --hard to-rebase-orig &&
+	git pull --rebase &&
+	test "conflicting modification" = "$(cat file)" &&
+	test file = $(cat file2) &&
+	git checkout to-rebase2 &&
+	git pull --rebase me copy
+
+'
+
 test_expect_success 'pull --rebase dies early with dirty working directory' '
 
+	git rebase --abort &&
+	git checkout to-rebase &&
 	git update-ref refs/remotes/me/copy copy^ &&
 	COPY=$(git rev-parse --verify me/copy) &&
 	git rebase --onto $COPY copy &&
-- 
1.6.3.1.308.g426b5

```

## Johannes Schindelin, 2009-06-05 23:22

Subject: Re: [PATCH 2/3] pull --rebase: Add support for rebased default upstream
Message-ID: <alpine.DEB.1.00.0906060120140.26154@pacific.mpi-cbg.de>
URL: https://gitlist.dev/e/alpine.DEB.1.00.0906060120140.26154%40pacific.mpi-cbg.de
In-Reply-To: <1244231617-17754-2-git-send-email-santi@agolina.net>

```
Hi,

On Fri, 5 Jun 2009, Santi Béjar wrote:

> Also add a test to check for this case and another one (failing) to
> test rebasing two branches on top of a rebased upstream using just
> 'git pull --rebase'.
> 
> Signed-off-by: Santi Béjar <santi@agolina.net>

Either I am a stupid moron (which is a completely valid suggestion) or 
this commit message lacks in detail severely.

For example, when I "git pull --rebase junio next" and "next" was rebased, 
it works _perfectly_, so I do not see any need for a fix.

Further, this:

> ---
>  git-parse-remote.sh |    8 +++++++-
>  t/t5520-pull.sh     |   29 +++++++++++++++++++++++++++++
>  2 files changed, 36 insertions(+), 1 deletions(-)

... suggests to me that pull --rebase is not even affected by your patch.  
So maybe you want to clarify so much that even stupid morons understand 
what you want to achieve, and how.

Ciao,
Dscho
```

## Santi Béjar, 2009-06-06 08:00

Subject: Re: [PATCH 2/3] pull --rebase: Add support for rebased default upstream
Message-ID: <adf1fd3d0906060100vc04032eh6315d336ef619402@mail.gmail.com>
URL: https://gitlist.dev/e/adf1fd3d0906060100vc04032eh6315d336ef619402%40mail.gmail.com
In-Reply-To: <alpine.DEB.1.00.0906060120140.26154@pacific.mpi-cbg.de>

```
2009/6/6 Johannes Schindelin <Johannes.Schindelin@gmx.de>:
> Hi,
>
> On Fri, 5 Jun 2009, Santi Béjar wrote:
>
>> Also add a test to check for this case and another one (failing) to
>> test rebasing two branches on top of a rebased upstream using just
>> 'git pull --rebase'.
>>
>> Signed-off-by: Santi Béjar <santi@agolina.net>
>
> Either I am a stupid moron (which is a completely valid suggestion) or
> this commit message lacks in detail severely.
>
> For example, when I "git pull --rebase junio next" and "next" was rebased,
> it works _perfectly_, so I do not see any need for a fix.

It is for the default upstream (with no arguments), so before this patch:

git pull --rebase

did not work with a rebased upstream.

But you are right, the commit message can be improved a lot. I've
redone this patch series so much that at the end the commit message
lack details.
>
> Further, this:
>
>> ---
>>  git-parse-remote.sh |    8 +++++++-
>>  t/t5520-pull.sh     |   29 +++++++++++++++++++++++++++++
>>  2 files changed, 36 insertions(+), 1 deletions(-)
>
> ... suggests to me that pull --rebase is not even affected by your patch.

It modifies a function used in git pull --rebase.

> So maybe you want to clarify so much that even stupid morons understand
> what you want to achieve, and how.

OK, I'll try.

parse-remote: support default reflist in get_remote_merge_branch

Expand get_remote_merge_branch to compute the tracking branch to merge
when called without arguments (or only the remote name). This allows
"git pull --rebase" without arguments (default upstream branch) to
work with a rebased upstream.

Santi

```
