path: root/t/
diff options
authorPhillip Wood <>2020-11-04 15:29:37 (GMT)
committerJunio C Hamano <>2020-11-04 22:10:41 (GMT)
commite100bea48102dca7e21359993085e89c7f154f9d (patch)
treea21bd9a41d2c961a46298747a3bdb20a850e2888 /t/
parentb927c80531cca9b9107754186532e8cb00884008 (diff)
rebase -i: stop overwriting ORIG_HEAD buffer
After rebasing, ORIG_HEAD is supposed to point to the old HEAD of the rebased branch. The code used find_unique_abbrev() to obtain the object name of the old HEAD and wrote to both .git/rebase-merge/orig-head (used by `rebase --abort` to go back to the previous state) and to ORIG_HEAD. The buffer find_unique_abbrev() gives back is volatile, unfortunately, and was overwritten after the former file is written but before ORIG_FILE is written, leaving an incorrect object name in it. Avoid relying on the volatile buffer of find_unique_abbrev(), and instead supply our own buffer to keep the object name. I think that all of the users of head_hash should actually be using opts->orig_head instead as passing a string rather than a struct object_id around is a hang over from the scripted implementation. This patch just fixes the immediate bug and adds a regression test based on Caspar's reproduction example[1]. The users will be converted to use struct object_id and head_hash removed in the next few commits. [1] Reported-by: Caspar Duregger <> Signed-off-by: Phillip Wood <> Signed-off-by: Junio C Hamano <>
Diffstat (limited to 't/')
1 files changed, 11 insertions, 0 deletions
diff --git a/t/ b/t/
index 07a1617..1e56696 100755
--- a/t/
+++ b/t/
@@ -1797,6 +1797,17 @@ test_expect_success 'todo has correct onto hash' '
test_i18ngrep "^# Rebase ..* onto $onto" actual
+test_expect_success 'ORIG_HEAD is updated correctly' '
+ test_when_finished "git checkout master && git branch -D test-orig-head" &&
+ git checkout -b test-orig-head A &&
+ git commit --allow-empty -m A1 &&
+ git commit --allow-empty -m A2 &&
+ git commit --allow-empty -m A3 &&
+ git commit --allow-empty -m A4 &&
+ git rebase master &&
+ test_cmp_rev ORIG_HEAD test-orig-head@{1}
# This must be the last test in this file
test_expect_success '$EDITOR and friends are unchanged' '