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

[PATCH w/ test] rebase -p -i: handle "no changes" gracefully

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Dec 17, 2007, 21:01 UTC
Message-ID
<Pine.LNX.4.64.0712172100450.9446@racer.site>
In-Reply-To
<7vprx56pfn.fsf@gitster.siamese.dyndns.org>

Since commit 376ccb8cbb453343998e734d8a1ce79f57a4e092, unchanged SHA-1s are no longer mapped via $REWRITTEN. But the updating phase was not prepared for the old head not being rewritten.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
	On Mon, 17 Dec 2007, Junio C Hamano wrote:
	> Hmph, care to add a test to t3404?
	How about this?
 git-rebase--interactive.sh    |    7 ++++++-
 t/t3404-rebase-interactive.sh |    6 ++++++
 2 files changed, 12 insertions(+), 1 deletions(-)
diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
index f83e00f..cd7e43f 100755
--- a/git-rebase--interactive.sh
+++ b/git-rebase--interactive.sh
@@ -322,7 +322,12 @@ do_next () {
 		test -f "$DOTEST"/current-commit &&
 			current_commit=$(cat "$DOTEST"/current-commit) &&
 			git rev-parse HEAD > "$REWRITTEN"/$current_commit
-		NEWHEAD=$(cat "$REWRITTEN"/$OLDHEAD)
+		if test -f "$REWRITTEN"/$OLDHEAD
+		then
+			NEWHEAD=$(cat "$REWRITTEN"/$OLDHEAD)
+		else
+			NEWHEAD=$OLDHEAD
+		fi
 	else
 		NEWHEAD=$(git rev-parse HEAD)
 	fi &&
diff --git a/t/t3404-rebase-interactive.sh b/t/t3404-rebase-interactive.sh
index 907c7f9..74a7eb3 100755
--- a/t/t3404-rebase-interactive.sh
+++ b/t/t3404-rebase-interactive.sh
@@ -184,6 +184,12 @@ test_expect_success 'retain authorship when squashing' '
 	git show HEAD | grep "^Author: Twerp Snog"
 '
 
+test_expect_success '-p handles "no changes" gracefully' '
+	HEAD=$(git rev-parse HEAD) &&
+	git rebase -i -p HEAD^ &&
+	test $HEAD = $(git rev-parse HEAD)
+'
+
 test_expect_success 'preserve merges with -p' '
 	git checkout -b to-be-preserved master^ &&
 	: > unrelated-file &&
-- 
1.5.4.rc0.59.g1d10d
Previous: Junio C HamanoNext: Junio C Hamano
Message 6 of 7 in “[BUG?] git rebase -i”
  1. Pieter de BieDec 14, 2007
  2. Johannes SixtDec 14, 2007
  3. Pieter de BieDec 17, 2007
  4. rebase -p -i: handle "no changes" gracefullyJohannes Schindelin, Dec 17, 2007
  5. Junio C HamanoDec 17, 2007
  6. rebase -p -i: handle "no changes" gracefullyJohannes Schindelin, Dec 17, 2007
  7. Junio C HamanoDec 18, 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.