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

[PATCH v2 1/2] rebase -i -p: handle index and workdir correctly

From
Thomas Rast <trast@student.ethz.ch>
Date
Aug 13, 2008, 11:56 UTC
Message-ID
<23b4780a3a7bbe06f4157b6843d1d9dab26d7087.1218628444.git.trast@student.ethz.ch>
In-Reply-To
<200808131207.31616.trast@student.ethz.ch>

'git rebase -i -p' forgot to update the index and working directory during fast forwards. Fix this. Makes 'GIT_EDITOR=true rebase -i -p <ancestor>' a no-op again.

Also, it attempted to do a fast forward even if it was instructed not to commit (via -n). Fall back to the cherry-pick code path and let that handle the issue for us.

Signed-off-by: Thomas Rast <trast@student.ethz.ch>
---
 git-rebase--interactive.sh    |   13 ++++++++++++-
 t/t3404-rebase-interactive.sh |    6 ++++++
 2 files changed, 18 insertions(+), 1 deletions(-)
diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
index 4e334ba..1dc24b1 100755
--- a/git-rebase--interactive.sh
+++ b/git-rebase--interactive.sh
@@ -145,7 +145,16 @@ pick_one () {
 }
 
 pick_one_preserving_merges () {
-	case "$1" in -n) sha1=$2 ;; *) sha1=$1 ;; esac
+	fast_forward=t
+	case "$1" in
+	-n)
+		fast_forward=f
+		sha1=$2
+		;;
+	*)
+		sha1=$1
+		;;
+	esac
 	sha1=$(git rev-parse $sha1)
 
 	if test -f "$DOTEST"/current-commit
@@ -182,6 +191,8 @@ pick_one_preserving_merges () {
 	t)
 		output warn "Fast forward to $sha1"
 		test $preserve = f || echo $sha1 > "$REWRITTEN"/$sha1
+		output git reset --hard $sha1 ||
+			die "Cannot fast forward to $sha1"
 		;;
 	f)
 		test "a$1" = a-n && die "Refusing to squash a merge: $sha1"
diff --git a/t/t3404-rebase-interactive.sh b/t/t3404-rebase-interactive.sh
index ffe3dd9..4d62b9a 100755
--- a/t/t3404-rebase-interactive.sh
+++ b/t/t3404-rebase-interactive.sh
@@ -202,6 +202,9 @@ test_expect_success 'retain authorship when squashing' '
 test_expect_success '-p handles "no changes" gracefully' '
 	HEAD=$(git rev-parse HEAD) &&
 	git rebase -i -p HEAD^ &&
+	git update-index --refresh &&
+	git diff-files --quiet &&
+	git diff-index --quiet --cached HEAD -- &&
 	test $HEAD = $(git rev-parse HEAD)
 '
 
@@ -235,6 +238,9 @@ test_expect_success 'preserve merges with -p' '
 	git checkout -b to-be-rebased &&
 	test_tick &&
 	git rebase -i -p --onto branch1 master &&
+	git update-index --refresh &&
+	git diff-files --quiet &&
+	git diff-index --quiet --cached HEAD -- &&
 	test $(git rev-parse HEAD~6) = $(git rev-parse branch1) &&
 	test $(git rev-parse HEAD~4^2) = $(git rev-parse to-be-preserved) &&
 	test $(git rev-parse HEAD^^2^) = $(git rev-parse HEAD^^^) &&
-- 
1.6.0.rc2.36.g234a
Previous: Thomas RastNext: Thomas Rast
Message 5 of 10 in “[BUG?] rebase -i -p leaves index changed”
  1. Thomas RastAug 12, 2008
  2. 1/2 rebase -i -p: handle index and workdir correctlyThomas Rast, Aug 13, 2008
  3. 2/2 rebase -i -p: fix parent rewritingThomas Rast, Aug 13, 2008
  4. Thomas RastAug 13, 2008
  5. 1/2 rebase -i -p: handle index and workdir correctlyThomas Rast, Aug 13, 2008
  6. 2/2 rebase -i -p: fix parent rewritingThomas Rast, Aug 13, 2008
  7. Stephan BeyerAug 13, 2008
  8. 1/2 rebase -i -p: handle index and workdir correctlyThomas Rast, Aug 13, 2008
  9. 2/2 rebase -i -p: fix parent rewritingThomas Rast, Aug 13, 2008
  10. Stephan BeyerAug 13, 2008

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.