Skip to content

Commit 812a18b

Browse files
phillipwoodgitster
authored andcommitted
rebase --abort: cleanup refs/rewritten
When `rebase -r` finishes it removes any refs under refs/rewritten that it has created. However if the rebase is aborted these refs are not removed. This can cause problems for future rebases. For example I recently wanted to merge a updated version of a topic branch into an integration branch so ran `rebase -ir` and removed the picks and label for the topic branch from the todo list so that merge -C <old-merge> topic would pick up the new version of topic. Unfortunately refs/rewritten/topic already existed from a previous rebase that had been aborted so the rebase just used the old topic, not the new one. Signed-off-by: Phillip Wood <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 460bc3c commit 812a18b

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

builtin/rebase.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -769,9 +769,16 @@ static int finish_rebase(struct rebase_options *opts)
769769
* user should see them.
770770
*/
771771
run_command_v_opt(argv_gc_auto, RUN_GIT_CMD);
772-
strbuf_addstr(&dir, opts->state_dir);
773-
remove_dir_recursively(&dir, 0);
774-
strbuf_release(&dir);
772+
if (opts->type == REBASE_INTERACTIVE) {
773+
struct replay_opts replay = REPLAY_OPTS_INIT;
774+
775+
replay.action = REPLAY_INTERACTIVE_REBASE;
776+
sequencer_remove_state(&replay);
777+
} else {
778+
strbuf_addstr(&dir, opts->state_dir);
779+
remove_dir_recursively(&dir, 0);
780+
strbuf_release(&dir);
781+
}
775782

776783
return 0;
777784
}

t/t3430-rebase-merges.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,14 @@ test_expect_success 'refs/rewritten/* is worktree-local' '
224224
test_cmp_rev HEAD "$(cat wt/b)"
225225
'
226226

227+
test_expect_success '--abort cleans up refs/rewritten' '
228+
git checkout -b abort-cleans-refs-rewritten H &&
229+
GIT_SEQUENCE_EDITOR="echo break >>" git rebase -ir @^ &&
230+
git rev-parse --verify refs/rewritten/onto &&
231+
git rebase --abort &&
232+
test_must_fail git rev-parse --verify refs/rewritten/onto
233+
'
234+
227235
test_expect_success 'post-rewrite hook and fixups work for merges' '
228236
git checkout -b post-rewrite &&
229237
test_commit same1 &&

0 commit comments

Comments
 (0)