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

Re: [PATCH] Reallow git-rebase --interactive --continue if commit is unnecessary

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Dec 29, 2007, 13:26 UTC
Message-ID
<Pine.LNX.4.64.0712291418360.14355@wbgn129.biozentrum.uni-wuerzburg.de>
In-Reply-To
<7vr6h9m2zb.fsf@gitster.siamese.dyndns.org>
Hi,
On Wed, 26 Dec 2007, Junio C Hamano wrote:
Show 14 quoted lines
> Junio C Hamano <gitster@pobox.com> writes:
> 
> >  		# commit if necessary
> >
> > Ok, the user has prepared the index for us, and we are going to do some
> > tests and conditionally create commit.
> >
> >  		git rev-parse --verify HEAD > /dev/null &&
> >
> > Do we have HEAD commit?  Why check this --- we do not want to rebase
> > from the beginning of time?  No, that's not it.  If this fails, there is
> > something seriously wrong.  This is not about "will we make a commit?"
> > check at all.  This is a basic sanity check and if it fails we must
> > abort, not just skip.
Right.  My intention was to have a "|| die" at the end of the && cascade.
Show 9 quoted lines
> >
> >  		git update-index --refresh &&
> >  		git diff-files --quiet &&
> >
> > Is the work tree clean with respect to the index?  Why check this --- we
> > want to skip the commit if work tree is dirty?  Or is this trying to
> > enforce the invariant that during the rebase the work tree and index and
> > HEAD should all match?  If the latter, failure from this again is a
> > reason to abort.

Exactly. I wanted to make sure that the working directory is not different from what is in the index.

Show 65 quoted lines
> >  		! git diff-index --cached --quiet HEAD -- &&
> >
> > Do we have something to commit?  This needs to be checked so that we can
> > skip a commit that results in emptyness, so using this as a check to see
> > if we should commit makes sense.
> >
> >  		. "$DOTEST"/author-script && {
> >  			test ! -f "$DOTEST"/amend || git reset --soft HEAD^
> >  		} &&
> >
> > Find GIT_AUTHOR_* variables and if we are amending rewind the HEAD.  The
> > failure from this is a grave problem and reason to abort, isn't it?
> >
> >  		export GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL GIT_AUTHOR_DATE &&
> > 		git commit --no-verify -F "$DOTEST"/message -e
> >
> > Then we go on to create commit.  As you said, failure from this is a
> > grave error.
> 
> Any response to this or problems in the clean-up patch?
> 
> > ---
> >  git-rebase--interactive.sh |   29 +++++++++++++++++++----------
> >  1 files changed, 19 insertions(+), 10 deletions(-)
> >
> > diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
> > index 090c3e5..7aa4278 100755
> > --- a/git-rebase--interactive.sh
> > +++ b/git-rebase--interactive.sh
> > @@ -363,17 +363,26 @@ do
> >  
> >  		test -d "$DOTEST" || die "No interactive rebase running"
> >  
> > -		# commit if necessary
> > -		git rev-parse --verify HEAD > /dev/null &&
> > -		git update-index --refresh &&
> > -		git diff-files --quiet &&
> > -		! git diff-index --cached --quiet HEAD -- &&
> > -		. "$DOTEST"/author-script && {
> > -			test ! -f "$DOTEST"/amend || git reset --soft HEAD^
> > -		} &&
> > -		export GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL GIT_AUTHOR_DATE &&
> > -		if ! git commit --no-verify -F "$DOTEST"/message -e
> > +		# Sanity check
> > +		git rev-parse --verify HEAD >/dev/null ||
> > +			die "Cannot read HEAD"
> > +		git update-index --refresh && git diff-files --quiet ||
> > +			die "Working tree is dirty"
> > +
> > +		# do we have anything to commit?
> > +		if git diff-index --cached --quiet HEAD --
> >  		then
> > +			: Nothing to commit -- skip this
> > +		else
> > +			. "$DOTEST"/author-script ||
> > +				die "Cannot find the author identity"
> > +			if test -f "$DOTEST"/amend
> > +			then
> > +				git reset --soft HEAD^ ||
> > +				die "Cannot rewind the HEAD"
> > +			fi
> > +			export GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL GIT_AUTHOR_DATE &&
> > +			git commit --no-verify -F "$DOTEST"/message -e ||
> >  			die "Could not commit staged changes."
> >  		fi
Looks good to me!  And I'm sorry for taking so long to respond.

Ciao, Dscho

Previous: Junio C HamanoNext: Matthieu Moy
Message 8 of 28 in “git rebase -i / git-gui bug”
  1. Bernt HansenDec 20, 2007
  2. Bernt HansenDec 20, 2007
  3. Reallow git-rebase --interactive --continue if commit is unnecessaryShawn O. Pearce, Dec 20, 2007
  4. Junio C HamanoDec 20, 2007
  5. Shawn O. PearceDec 20, 2007
  6. Junio C HamanoDec 20, 2007
  7. Junio C HamanoDec 26, 2007
  8. Johannes SchindelinDec 29, 2007
  9. Matthieu MoyDec 20, 2007
  10. Force new line at end of commit messageBernt Hansen, Dec 24, 2007
  11. Johannes SchindelinDec 24, 2007
  12. Shawn O. PearceDec 25, 2007
  13. Junio C HamanoDec 25, 2007
  14. Bernt HansenDec 26, 2007
  15. Shawn O. PearceDec 27, 2007
  16. git-gui: Make commit log messages end with a newlineBernt Hansen, Dec 28, 2007
  17. Junio C HamanoDec 26, 2007
  18. Johannes SchindelinDec 29, 2007
  19. Junio C HamanoDec 30, 2007
  20. Johannes SchindelinDec 30, 2007
  21. Junio C HamanoDec 30, 2007
  22. Johannes SchindelinDec 30, 2007
  23. Junio C HamanoDec 30, 2007
  24. しらいしななこDec 30, 2007
  25. Junio C HamanoDec 30, 2007
  26. Junio C HamanoDec 30, 2007
  27. Johannes SchindelinDec 30, 2007
  28. Shawn O. PearceDec 25, 2007

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.