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

[PATCH] rebase --abort: do not update branch ref

From
Martin von Zweigbergk <martin.von.zweigbergk@gmail.com>
Date
Nov 21, 2010, 11:11 UTC
Message-ID
<1290337881-26449-1-git-send-email-martin.von.zweigbergk@gmail.com>

If a non-interactive rebase of a ref fails at commit X and is aborted by the user, the ref will be updated twice. First to point at X (with the reflog message "rebase finished: $head_name onto $onto"), and then back to $orig_head. It should not be updated at all.

Signed-off-by: Martin von Zweigbergk <martin.von.zweigbergk@gmail.com>
---
This patch unfortunately duplicates some code from
move_to_original_branch, but since I'm refactoring the rebase code quite
a bit, I don't want to change too much in this patch. I will see what I
can do to reduce the duplication after some of the refactoring.
 git-rebase.sh           |    9 +++++++--
 t/t3407-rebase-abort.sh |   11 +++++++++++
 2 files changed, 18 insertions(+), 2 deletions(-)
diff --git a/git-rebase.sh b/git-rebase.sh
index ec08f9c..3d194b1 100755
--- a/git-rebase.sh
+++ b/git-rebase.sh
@@ -278,12 +278,17 @@ do
 		if test -d "$dotest"
 		then
 			GIT_QUIET=$(cat "$dotest/quiet")
-			move_to_original_branch
 		else
 			dotest="$GIT_DIR"/rebase-apply
 			GIT_QUIET=$(cat "$dotest/quiet")
-			move_to_original_branch
 		fi
+		head_name="$(cat "$dotest"/head-name)" &&
+		case "$head_name" in
+		refs/*)
+			git symbolic-ref HEAD $head_name ||
+			die "Could not move back to $head_name"
+			;;
+		esac
 		git reset --hard $(cat "$dotest/orig-head")
 		rm -r "$dotest"
 		exit
diff --git a/t/t3407-rebase-abort.sh b/t/t3407-rebase-abort.sh
index fbb3f2e..f3250c3 100755
--- a/t/t3407-rebase-abort.sh
+++ b/t/t3407-rebase-abort.sh
@@ -72,6 +72,17 @@ testrebase() {
 		test $(git rev-parse to-rebase) = $(git rev-parse pre-rebase) &&
 		test ! -d "$dotest"
 	'
+
+	test_expect_success "rebase$type --abort does not update reflog" '
+		cd "$work_dir" &&
+		# Clean up the state from the previous one
+		git reset --hard pre-rebase &&
+		reflog_entries_before=$(git reflog show to-rebase | wc -l) &&
+		test_must_fail git rebase$type master &&
+		git rebase --abort &&
+		reflog_entries_after=$(git reflog show to-rebase | wc -l) &&
+		test $reflog_entries_before -eq $reflog_entries_after
+	'
 }
 
 testrebase "" .git/rebase-apply
-- 
1.7.3.2.190.gfb4ae
Next: Martin von Zweigbergk
Message 1 of 4 in “rebase --abort: do not update branch ref”
  1. rebase --abort: do not update branch refMartin von Zweigbergk, Nov 21, 2010
  2. t3407: make reflog check stricterMartin von Zweigbergk, Nov 21, 2010
  3. Junio C HamanoNov 22, 2010
  4. Martin von ZweigbergkNov 22, 2010

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.