Skip to content

Commit 0aaadc1

Browse files
committed
sequencer (rebase -i): update refs after a successful rebase
An interactive rebase operates on a detached HEAD (to keep the reflog of the original branch relatively clean), and updates the branch only at the end. Now that the sequencer learns to perform interactive rebases, it also needs to learn the trick to update the branch before removing the directory containing the state of the interactive rebase. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
1 parent f245ae0 commit 0aaadc1

1 file changed

Lines changed: 31 additions & 1 deletion

File tree

sequencer.c

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ static GIT_PATH_FUNC(stopped_sha, "rebase-merge/stopped-sha")
9696
* The following files are written by git-rebase just after parsing the
9797
* command-line (and are only consumed, not modified, by the sequencer).
9898
*/
99+
static GIT_PATH_FUNC(head_name, "rebase-merge/head-name")
100+
static GIT_PATH_FUNC(onto, "rebase-merge/onto")
99101
static GIT_PATH_FUNC(orig_head, "rebase-merge/orig-head")
100102
static GIT_PATH_FUNC(git_path_rebase_verbose, "rebase-merge/verbose") /* TODO: turn into opt */
101103

@@ -1599,12 +1601,39 @@ static int pick_commits(struct todo_list *todo_list, struct replay_opts *opts)
15991601
}
16001602

16011603
if (IS_REBASE_I()) {
1602-
struct strbuf buf = STRBUF_INIT;
1604+
struct strbuf head_ref = STRBUF_INIT, buf = STRBUF_INIT;
16031605

16041606
/* Stopped in the middle, as planned? */
16051607
if (todo_list->current < todo_list->nr)
16061608
return 0;
16071609

1610+
if (strbuf_read_file(&head_ref, head_name(), 64) > 0 &&
1611+
starts_with(head_ref.buf, "refs/")) {
1612+
unsigned char head[20], orig[20];
1613+
1614+
strbuf_rtrim(&head_ref);
1615+
if (get_sha1("HEAD", head))
1616+
return error("Cannot read HEAD");
1617+
if (strbuf_read_file(&buf, orig_head(), 41) <= 0 ||
1618+
get_sha1_hex(buf.buf, orig))
1619+
return error("Could not read orig-head");
1620+
strbuf_addf(&buf, "rebase -i (finish): %s onto ",
1621+
head_ref.buf);
1622+
strbuf_read_file(&buf, onto(), 64);
1623+
if (update_ref(buf.buf, head_ref.buf, head, orig,
1624+
REF_NODEREF, UPDATE_REFS_MSG_ON_ERR))
1625+
return error("Could not update %s",
1626+
head_ref.buf);
1627+
strbuf_reset(&buf);
1628+
strbuf_addf(&buf,
1629+
"rebase -i (finish): returning to %s",
1630+
head_ref.buf);
1631+
if (create_symref("HEAD", head_ref.buf, buf.buf))
1632+
return error("Could not update HEAD to %s",
1633+
head_ref.buf);
1634+
strbuf_reset(&buf);
1635+
}
1636+
16081637
if (file_exists(git_path_rebase_verbose())) {
16091638
const char *argv[] = {
16101639
"diff-tree", "--stat", NULL, NULL
@@ -1619,6 +1648,7 @@ static int pick_commits(struct todo_list *todo_list, struct replay_opts *opts)
16191648
strbuf_reset(&buf);
16201649
}
16211650
strbuf_release(&buf);
1651+
strbuf_release(&head_ref);
16221652
}
16231653

16241654
/*

0 commit comments

Comments
 (0)