Skip to content

Commit 789b1f7

Browse files
committed
Merge branch 'js/rebase-i-break'
"git rebase -i" learned a new insn, 'break', that the user can insert in the to-do list. Upon hitting it, the command returns control back to the user. * js/rebase-i-break: rebase -i: introduce the 'break' command rebase -i: clarify what happens on a failed `exec`
2 parents b78c5fe + 71f8246 commit 789b1f7

File tree

5 files changed

+40
-3
lines changed

5 files changed

+40
-3
lines changed

Documentation/git-rebase.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,8 @@ See also INCOMPATIBLE OPTIONS below.
441441
--exec <cmd>::
442442
Append "exec <cmd>" after each line creating a commit in the
443443
final history. <cmd> will be interpreted as one or more shell
444-
commands.
444+
commands. Any command that fails will interrupt the rebase,
445+
with exit code 1.
445446
+
446447
You may execute several commands by either using one instance of `--exec`
447448
with several commands:
@@ -641,6 +642,9 @@ By replacing the command "pick" with the command "edit", you can tell
641642
the files and/or the commit message, amend the commit, and continue
642643
rebasing.
643644

645+
To interrupt the rebase (just like an "edit" command would do, but without
646+
cherry-picking any commit first), use the "break" command.
647+
644648
If you just want to edit the commit message for a commit, replace the
645649
command "pick" with the command "reword".
646650

rebase-interactive.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ void append_todo_help(unsigned edit_todo, unsigned keep_empty,
1414
"s, squash <commit> = use commit, but meld into previous commit\n"
1515
"f, fixup <commit> = like \"squash\", but discard this commit's log message\n"
1616
"x, exec <command> = run command (the rest of the line) using shell\n"
17+
"b, break = stop here (continue rebase later with 'git rebase --continue')\n"
1718
"d, drop <commit> = remove commit\n"
1819
"l, label <label> = label current HEAD with a name\n"
1920
"t, reset <label> = reset HEAD to a label\n"

sequencer.c

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1458,6 +1458,7 @@ enum todo_command {
14581458
TODO_SQUASH,
14591459
/* commands that do something else than handling a single commit */
14601460
TODO_EXEC,
1461+
TODO_BREAK,
14611462
TODO_LABEL,
14621463
TODO_RESET,
14631464
TODO_MERGE,
@@ -1479,6 +1480,7 @@ static struct {
14791480
{ 'f', "fixup" },
14801481
{ 's', "squash" },
14811482
{ 'x', "exec" },
1483+
{ 'b', "break" },
14821484
{ 'l', "label" },
14831485
{ 't', "reset" },
14841486
{ 'm', "merge" },
@@ -2004,7 +2006,7 @@ static int parse_insn_line(struct todo_item *item, const char *bol, char *eol)
20042006
padding = strspn(bol, " \t");
20052007
bol += padding;
20062008

2007-
if (item->command == TODO_NOOP) {
2009+
if (item->command == TODO_NOOP || item->command == TODO_BREAK) {
20082010
if (bol != eol)
20092011
return error(_("%s does not accept arguments: '%s'"),
20102012
command_to_string(item->command), bol);
@@ -3393,6 +3395,24 @@ static int checkout_onto(struct replay_opts *opts,
33933395
return update_ref(NULL, "ORIG_HEAD", &oid, NULL, 0, UPDATE_REFS_MSG_ON_ERR);
33943396
}
33953397

3398+
static int stopped_at_head(void)
3399+
{
3400+
struct object_id head;
3401+
struct commit *commit;
3402+
struct commit_message message;
3403+
3404+
if (get_oid("HEAD", &head) ||
3405+
!(commit = lookup_commit(the_repository, &head)) ||
3406+
parse_commit(commit) || get_message(commit, &message))
3407+
fprintf(stderr, _("Stopped at HEAD\n"));
3408+
else {
3409+
fprintf(stderr, _("Stopped at %s\n"), message.label);
3410+
free_message(commit, &message);
3411+
}
3412+
return 0;
3413+
3414+
}
3415+
33963416
static const char rescheduled_advice[] =
33973417
N_("Could not execute the todo command\n"
33983418
"\n"
@@ -3439,6 +3459,9 @@ static int pick_commits(struct todo_list *todo_list, struct replay_opts *opts)
34393459
unlink(rebase_path_stopped_sha());
34403460
unlink(rebase_path_amend());
34413461
delete_ref(NULL, "REBASE_HEAD", NULL, REF_NO_DEREF);
3462+
3463+
if (item->command == TODO_BREAK)
3464+
return stopped_at_head();
34423465
}
34433466
if (item->command <= TODO_SQUASH) {
34443467
if (is_rebase_i(opts))

t/lib-rebase.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ set_fake_editor () {
4949
case $line in
5050
pick|squash|fixup|edit|reword|drop)
5151
action="$line";;
52-
exec*)
52+
exec*|break)
5353
echo "$line" | sed 's/_/ /g' >> "$1";;
5454
"#")
5555
echo '# comment' >> "$1";;

t/t3418-rebase-continue.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,5 +241,14 @@ test_rerere_autoupdate -m
241241
GIT_SEQUENCE_EDITOR=: && export GIT_SEQUENCE_EDITOR
242242
test_rerere_autoupdate -i
243243
test_rerere_autoupdate --preserve-merges
244+
unset GIT_SEQUENCE_EDITOR
245+
246+
test_expect_success 'the todo command "break" works' '
247+
rm -f execed &&
248+
FAKE_LINES="break exec_>execed" git rebase -i HEAD &&
249+
test_path_is_missing execed &&
250+
git rebase --continue &&
251+
test_path_is_file execed
252+
'
244253

245254
test_done

0 commit comments

Comments
 (0)