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

Re: rebase problems

From
Junio C Hamano <junkio@cox.net>
Date
Nov 28, 2005, 21:02 UTC
Message-ID
<7vhd9wscz4.fsf@assigned-by-dhcp.cox.net>
In-Reply-To
<20051128202428.GA8383MdfPADPa@greensroom.kotnet.org>
Sven Verdoolaege <skimo@kotnet.org> writes:
Show 14 quoted lines
> On Mon, Nov 28, 2005 at 12:19:40PM -0800, Junio C Hamano wrote:
>> The output seems very inconsistent I am not sure why the first
>> message says "Applying HEAD~2", not HEAD~6.    What patches do
>> you see in .dotest/ directory, and are they numbered in the
>> right order?  HEAD~6 should be numbered 0001 and that should be
>> the first one that was applied.
>
> Ah!  It seems .dotest still contained some stuff from a previous
> (expectedly) failed rebase.
>
> Rebase worked after rm -rf'ing .dotest
>
> Maybe rebase should clean up .dotest or at least warn about
> an existing .dotest ?
Thanks, you are right.  I was coming to the same conclusion.
There are a few more problems in the current rebase.
 - If the branch being rebased is fully in sync with the master
   (i.e. there is no patch to apply), it fails with a mysterious
   message "fatal: cannot read mbox".
 - If the branch being rebased is already a proper descendant of
   the master, it still goes ahead and rebases.  This is
   unnecessary.
I think something like this is necessary.

-- >8 -- [PATCH] rebase: one safety net, one bugfix and one optimization.

When a .dotest from a previously failed rebase or patch application exists, rebase got confused and tried to apply mixture of what was already there and what is being rebased. Check the existence of the directory and barf.

It failed with an mysterious "fatal: cannot read mbox" message if the branch being rebased is fully in sync with the base. Also if the branch is a proper descendant of the base, there is no need to run rebase logic. Prevent these from happening by checking where the merge-base is.

Signed-off-by: Junio C Hamano <junkio@cox.net>
---
 git-rebase.sh |   28 +++++++++++++++++++++++++++-
 1 files changed, 27 insertions(+), 1 deletions(-)

applies-to: fe523a4df93cce3e5c5b0266b9d3f1cbea009afa 7f4bd5d831ea838668d1de5f5af022f763230eee

diff --git a/git-rebase.sh b/git-rebase.sh
index 2bc3a12..638ff0d 100755
--- a/git-rebase.sh
+++ b/git-rebase.sh
@@ -5,9 +5,25 @@
 
 . git-sh-setup
 
-# The other head is given
+# Make sure we do not have .dotest
+if mkdir .dotest
+then
+	rmdir .dotest
+else
+	echo >&2 '
+It seems that I cannot create a .dotest directory, and I wonder if you
+are in the middle of patch application or another rebase.  If that is not
+the case, please rm -fr .dotest and run me again.  I am stopping in case
+you still have something valuable there.'
+	exit 1
+fi
+
+# The other head is given.  Make sure it is valid.
 other=$(git-rev-parse --verify "$1^0") || exit
 
+# Make sure we have HEAD that is valid.
+head=$(git-rev-parse --verify "HEAD^0") || exit
+
 # The tree must be really really clean.
 git-update-index --refresh || exit
 diff=$(git-diff-index --cached --name-status -r HEAD)
@@ -23,6 +39,16 @@ case "$#" in
 	git-checkout "$2" || exit
 esac
 
+# If the HEAD is a proper descendant of $other, we do not even need
+# to rebase.  Make sure we do not do needless rebase.  In such a
+# case, merge-base should be the same as "$other".
+mb=$(git-merge-base "$other" "$head")
+if test "$mb" = "$other"
+then
+	echo >&2 "Current branch `git-symbolic-ref HEAD` is up to date."
+	exit 0
+fi
+
 # Rewind the head to "$other"
 git-reset --hard "$other"
 git-format-patch -k --stdout --full-index "$other" ORIG_HEAD |
---
0.99.9.GIT
Previous: Sven Verdoolaege
Message 4 of 4 in “rebase problems”
  1. Sven VerdoolaegeNov 28, 2005
  2. Junio C HamanoNov 28, 2005
  3. Sven VerdoolaegeNov 28, 2005
  4. Junio C HamanoNov 28, 2005

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.