Subject: Re: [PATCH 0/3] Reject non-ff pulls by default

From: John Keeping <[email-masked]>
Date: Sat, 7 Sep 2013 12:07:45 +0100

On Fri, Sep 06, 2013 at 03:14:25PM -0700, Junio C Hamano wrote:
> Jonathan Nieder <[email-masked]> writes:
> 
> > John Keeping wrote:
> >> On Thu, Sep 05, 2013 at 12:18:45PM -0700, Junio C Hamano wrote:
> >
> >>> I somehow thought that rebase by default looked in the reflog to do
> >>> exactly that. Perhaps I am not remembering correctly.
> >>
> >> It just does @{upstream} by default, which tends to get messy if the
> >> upstream has been rewritten.
> >
> > Maybe Junio is thinking of 'git pull --rebase', which walks the reflog
> > until it finds an ancestor of the current branch and uses that as the
> > <upstream> parameter to rebase.
> 
> You're right.
> 
> It makes me wonder why we did that one inside pull and not in
> rebase, though.

I'd never realised "pull --rebase" does that - it's exactly what I want
sometimes and I normally do fetch followed by rebase to get more control
over the process.

Perhaps we should do something like this (with added tests and
documentation)?

-- >8 --
Subject: [PATCH] rebase: use reflog to find common base with upstream

Signed-off-by: John Keeping <[email-masked]>
---
 git-rebase.sh | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/git-rebase.sh b/git-rebase.sh
index 8d7659a..5e3013d 100755
--- a/git-rebase.sh
+++ b/git-rebase.sh
@@ -428,6 +428,14 @@ then
 			error_on_missing_default_upstream "rebase" "rebase" \
 				"against" "git rebase <branch>"
 		fi
+		for reflog in $(git rev-list -g "$upstream_name" 2>/dev/null)
+		do
+			if test "$reflog" = "$(git merge-base "$reflog" HEAD)"
+			then
+				upstream_name=$reflog
+				break
+			fi
+		done
 		;;
 	*)	upstream_name="$1"
 		shift
-- 
1.8.4.239.g2332621