Skip to content

Commit

Permalink
sequencer: make it clearer that commit descriptions are just comments
Browse files Browse the repository at this point in the history
Every once in a while, users report that editing the commit summaries
in the todo list does not get reflected in the rebase operation,
suggesting that users are (a) only using one-line commit messages, and
(b) not understanding that the commit summaries are merely helpful
comments to help them find the right hashes.

It may be difficult to correct users' poor commit messages, but we can
at least try to make it clearer that the commit summaries are not
directives of some sort by inserting a comment character.
  • Loading branch information
newren committed Jul 15, 2022
1 parent a9ee2b3 commit f1ae608
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 73 deletions.
16 changes: 11 additions & 5 deletions sequencer.c
Original file line number Diff line number Diff line change
Expand Up @@ -5189,11 +5189,11 @@ static int make_script_with_merges(struct pretty_print_context *pp,

/* Create a label */
strbuf_reset(&label);
if (skip_prefix(oneline.buf, "Merge ", &p1) &&
if (skip_prefix(oneline.buf, "# Merge ", &p1) &&
(p1 = strchr(p1, '\'')) &&
(p2 = strchr(++p1, '\'')))
strbuf_add(&label, p1, p2 - p1);
else if (skip_prefix(oneline.buf, "Merge pull request ",
else if (skip_prefix(oneline.buf, "# Merge pull request ",
&p1) &&
(p1 = strstr(p1, " from ")))
strbuf_addstr(&label, p1 + strlen(" from "));
Expand All @@ -5220,7 +5220,7 @@ static int make_script_with_merges(struct pretty_print_context *pp,

strbuf_addstr(&buf, label_oid(oid, label.buf, &state));
}
strbuf_addf(&buf, " # %s", oneline.buf);
strbuf_addf(&buf, " %s", oneline.buf);

FLEX_ALLOC_STR(entry, string, buf.buf);
oidcpy(&entry->entry.oid, &commit->object.oid);
Expand Down Expand Up @@ -5302,7 +5302,7 @@ static int make_script_with_merges(struct pretty_print_context *pp,
else {
strbuf_reset(&oneline);
pretty_print_commit(pp, commit, &oneline);
strbuf_addf(out, "%s %s # %s\n",
strbuf_addf(out, "%s %s %s\n",
cmd_reset, to, oneline.buf);
}
}
Expand Down Expand Up @@ -5365,8 +5365,14 @@ int sequencer_make_script(struct repository *r, struct strbuf *out, int argc,
git_config_get_string("rebase.instructionFormat", &format);
if (!format || !*format) {
free(format);
format = xstrdup("%s");
format = xstrdup("# %s");
}
if (*format != '#') {
char *temp = format;
format = xstrfmt("# %s", temp);
free(temp);
}

get_commit_format(format, &revs);
free(format);
pp.fmt = revs.commit_format;
Expand Down
28 changes: 14 additions & 14 deletions t/t3404-rebase-interactive.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1388,7 +1388,7 @@ test_expect_success 'rebase -i respects rebase.missingCommitsCheck = warn' '
cat >expect <<-EOF &&
Warning: some commits may have been dropped accidentally.
Dropped commits (newer to older):
- $(git rev-list --pretty=oneline --abbrev-commit -1 primary)
- $(git log --format="%h # %s" -1 primary)
To avoid this message, use "drop" to explicitly remove a commit.
EOF
test_config rebase.missingCommitsCheck warn &&
Expand All @@ -1406,8 +1406,8 @@ test_expect_success 'rebase -i respects rebase.missingCommitsCheck = error' '
cat >expect <<-EOF &&
Warning: some commits may have been dropped accidentally.
Dropped commits (newer to older):
- $(git rev-list --pretty=oneline --abbrev-commit -1 primary)
- $(git rev-list --pretty=oneline --abbrev-commit -1 primary~2)
- $(git log --format="%h # %s" -1 primary)
- $(git log --format="%h # %s" -1 primary~2)
To avoid this message, use "drop" to explicitly remove a commit.
Use '\''git config rebase.missingCommitsCheck'\'' to change the level of warnings.
Expand Down Expand Up @@ -1449,11 +1449,11 @@ test_expect_success 'rebase --edit-todo respects rebase.missingCommitsCheck = ig

test_expect_success 'rebase --edit-todo respects rebase.missingCommitsCheck = warn' '
cat >expect <<-EOF &&
error: invalid line 1: badcmd $(git rev-list --pretty=oneline --abbrev-commit -1 primary~4)
error: invalid line 1: badcmd $(git log --format="%h # %s" -1 primary~4)
Warning: some commits may have been dropped accidentally.
Dropped commits (newer to older):
- $(git rev-list --pretty=oneline --abbrev-commit -1 primary)
- $(git rev-list --pretty=oneline --abbrev-commit -1 primary~4)
- $(git log --format="%h # %s" -1 primary)
- $(git log --format="%h # %s" -1 primary~4)
To avoid this message, use "drop" to explicitly remove a commit.
EOF
head -n4 expect >expect.2 &&
Expand Down Expand Up @@ -1483,11 +1483,11 @@ test_expect_success 'rebase --edit-todo respects rebase.missingCommitsCheck = wa

test_expect_success 'rebase --edit-todo respects rebase.missingCommitsCheck = error' '
cat >expect <<-EOF &&
error: invalid line 1: badcmd $(git rev-list --pretty=oneline --abbrev-commit -1 primary~4)
error: invalid line 1: badcmd $(git log --format="%h # %s" -1 primary~4)
Warning: some commits may have been dropped accidentally.
Dropped commits (newer to older):
- $(git rev-list --pretty=oneline --abbrev-commit -1 primary)
- $(git rev-list --pretty=oneline --abbrev-commit -1 primary~4)
- $(git log --format="%h # %s" -1 primary)
- $(git log --format="%h # %s" -1 primary~4)
To avoid this message, use "drop" to explicitly remove a commit.
Use '\''git config rebase.missingCommitsCheck'\'' to change the level of warnings.
Expand Down Expand Up @@ -1560,11 +1560,11 @@ test_expect_success 'respects rebase.abbreviateCommands with fixup, squash and e
test_commit "fixup! first" file2.txt "first line again" first_fixup &&
test_commit "squash! second" file1.txt "another line here" second_squash &&
cat >expected <<-EOF &&
p $(git rev-list --abbrev-commit -1 first) first
f $(git rev-list --abbrev-commit -1 first_fixup) fixup! first
p $(git rev-list --abbrev-commit -1 first) # first
f $(git rev-list --abbrev-commit -1 first_fixup) # fixup! first
x git show HEAD
p $(git rev-list --abbrev-commit -1 second) second
s $(git rev-list --abbrev-commit -1 second_squash) squash! second
p $(git rev-list --abbrev-commit -1 second) # second
s $(git rev-list --abbrev-commit -1 second_squash) # squash! second
x git show HEAD
EOF
git checkout abbrevcmd &&
Expand All @@ -1583,7 +1583,7 @@ test_expect_success 'static check of bad command' '
set_fake_editor &&
test_must_fail env FAKE_LINES="1 2 3 bad 4 5" \
git rebase -i --root 2>actual &&
test_i18ngrep "badcmd $(git rev-list --oneline -1 primary~1)" \
test_i18ngrep "badcmd $(git log --format="%h # %s" -1 primary~1)" \
actual &&
test_i18ngrep "You can fix this with .git rebase --edit-todo.." \
actual &&
Expand Down
10 changes: 5 additions & 5 deletions t/t3415-rebase-autosquash.sh
Original file line number Diff line number Diff line change
Expand Up @@ -280,10 +280,10 @@ test_auto_fixup_fixup () {
parent2=$(git rev-parse --short HEAD^^) &&
parent3=$(git rev-parse --short HEAD^^^) &&
cat >expected <<-EOF &&
pick $parent3 first commit
$1 $parent1 $1! first
$1 $head $1! $2! first
pick $parent2 second commit
pick $parent3 # first commit
$1 $parent1 # $1! first
$1 $head # $1! $2! first
pick $parent2 # second commit
EOF
test_cmp expected actual
) &&
Expand Down Expand Up @@ -358,7 +358,7 @@ test_expect_success 'autosquash with empty custom instructionFormat' '
set_cat_todo_editor &&
test_must_fail git -c rebase.instructionFormat= \
rebase --autosquash --force-rebase -i HEAD^ >actual &&
git log -1 --format="pick %h %s" >expect &&
git log -1 --format="pick %h # %s" >expect &&
test_cmp expect actual
)
'
Expand Down
10 changes: 5 additions & 5 deletions t/t3430-rebase-merges.sh
Original file line number Diff line number Diff line change
Expand Up @@ -106,18 +106,18 @@ test_expect_success 'generate correct todo list' '
label onto
reset onto
pick $b B
pick $b # B
label E
reset onto
pick $c C
pick $c # C
label branch-point
pick $f F
pick $g G
pick $f # F
pick $g # G
label H
reset branch-point # C
pick $d D
pick $d # D
merge -C $e E # E
merge -C $h H # H
Expand Down
2 changes: 1 addition & 1 deletion t/t5520-pull.sh
Original file line number Diff line number Diff line change
Expand Up @@ -796,7 +796,7 @@ test_expect_success 'git pull --rebase does not reapply old patches' '
cd dst &&
test_must_fail git pull --rebase &&
cat .git/rebase-merge/done .git/rebase-merge/git-rebase-todo >work &&
grep -v -e \# -e ^$ work >patches &&
sed -e s/#.*// work | grep -v ^$ >patches &&
test_line_count = 1 patches &&
rm -f work
)
Expand Down
86 changes: 43 additions & 43 deletions t/t7512-status-help.sh
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ test_expect_success 'status during rebase -i when conflicts unresolved' '
cat >expected <<EOF &&
interactive rebase in progress; onto $ONTO
Last command done (1 command done):
pick $LAST_COMMIT one_second
pick $LAST_COMMIT # one_second
No commands remaining.
You are currently rebasing branch '\''rebase_i_conflicts_second'\'' on '\''$ONTO'\''.
(fix conflicts and then run "git rebase --continue")
Expand Down Expand Up @@ -168,7 +168,7 @@ test_expect_success 'status during rebase -i after resolving conflicts' '
cat >expected <<EOF &&
interactive rebase in progress; onto $ONTO
Last command done (1 command done):
pick $LAST_COMMIT one_second
pick $LAST_COMMIT # one_second
No commands remaining.
You are currently rebasing branch '\''rebase_i_conflicts_second'\'' on '\''$ONTO'\''.
(all conflicts fixed: run "git rebase --continue")
Expand Down Expand Up @@ -200,8 +200,8 @@ test_expect_success 'status when rebasing -i in edit mode' '
cat >expected <<EOF &&
interactive rebase in progress; onto $ONTO
Last commands done (2 commands done):
pick $COMMIT2 two_rebase_i
edit $COMMIT3 three_rebase_i
pick $COMMIT2 # two_rebase_i
edit $COMMIT3 # three_rebase_i
No commands remaining.
You are currently editing a commit while rebasing branch '\''rebase_i_edit'\'' on '\''$ONTO'\''.
(use "git commit --amend" to amend the current commit)
Expand Down Expand Up @@ -233,10 +233,10 @@ test_expect_success 'status when splitting a commit' '
cat >expected <<EOF &&
interactive rebase in progress; onto $ONTO
Last commands done (2 commands done):
pick $COMMIT2 two_split
edit $COMMIT3 three_split
pick $COMMIT2 # two_split
edit $COMMIT3 # three_split
Next command to do (1 remaining command):
pick $COMMIT4 four_split
pick $COMMIT4 # four_split
(use "git rebase --edit-todo" to view and edit)
You are currently splitting a commit while rebasing branch '\''split_commit'\'' on '\''$ONTO'\''.
(Once your working directory is clean, run "git rebase --continue")
Expand Down Expand Up @@ -271,8 +271,8 @@ test_expect_success 'status after editing the last commit with --amend during a
cat >expected <<EOF &&
interactive rebase in progress; onto $ONTO
Last commands done (3 commands done):
pick $COMMIT3 three_amend
edit $COMMIT4 four_amend
pick $COMMIT3 # three_amend
edit $COMMIT4 # four_amend
(see more in file .git/rebase-merge/done)
No commands remaining.
You are currently editing a commit while rebasing branch '\''amend_last'\'' on '\''$ONTO'\''.
Expand Down Expand Up @@ -309,10 +309,10 @@ test_expect_success 'status: (continue first edit) second edit' '
cat >expected <<EOF &&
interactive rebase in progress; onto $ONTO
Last commands done (2 commands done):
edit $COMMIT2 two_edits
edit $COMMIT3 three_edits
edit $COMMIT2 # two_edits
edit $COMMIT3 # three_edits
Next command to do (1 remaining command):
pick $COMMIT4 four_edits
pick $COMMIT4 # four_edits
(use "git rebase --edit-todo" to view and edit)
You are currently editing a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
(use "git commit --amend" to amend the current commit)
Expand Down Expand Up @@ -340,10 +340,10 @@ test_expect_success 'status: (continue first edit) second edit and split' '
cat >expected <<EOF &&
interactive rebase in progress; onto $ONTO
Last commands done (2 commands done):
edit $COMMIT2 two_edits
edit $COMMIT3 three_edits
edit $COMMIT2 # two_edits
edit $COMMIT3 # three_edits
Next command to do (1 remaining command):
pick $COMMIT4 four_edits
pick $COMMIT4 # four_edits
(use "git rebase --edit-todo" to view and edit)
You are currently splitting a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
(Once your working directory is clean, run "git rebase --continue")
Expand Down Expand Up @@ -375,10 +375,10 @@ test_expect_success 'status: (continue first edit) second edit and amend' '
cat >expected <<EOF &&
interactive rebase in progress; onto $ONTO
Last commands done (2 commands done):
edit $COMMIT2 two_edits
edit $COMMIT3 three_edits
edit $COMMIT2 # two_edits
edit $COMMIT3 # three_edits
Next command to do (1 remaining command):
pick $COMMIT4 four_edits
pick $COMMIT4 # four_edits
(use "git rebase --edit-todo" to view and edit)
You are currently editing a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
(use "git commit --amend" to amend the current commit)
Expand Down Expand Up @@ -406,10 +406,10 @@ test_expect_success 'status: (amend first edit) second edit' '
cat >expected <<EOF &&
interactive rebase in progress; onto $ONTO
Last commands done (2 commands done):
edit $COMMIT2 two_edits
edit $COMMIT3 three_edits
edit $COMMIT2 # two_edits
edit $COMMIT3 # three_edits
Next command to do (1 remaining command):
pick $COMMIT4 four_edits
pick $COMMIT4 # four_edits
(use "git rebase --edit-todo" to view and edit)
You are currently editing a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
(use "git commit --amend" to amend the current commit)
Expand Down Expand Up @@ -438,10 +438,10 @@ test_expect_success 'status: (amend first edit) second edit and split' '
cat >expected <<EOF &&
interactive rebase in progress; onto $ONTO
Last commands done (2 commands done):
edit $COMMIT2 two_edits
edit $COMMIT3 three_edits
edit $COMMIT2 # two_edits
edit $COMMIT3 # three_edits
Next command to do (1 remaining command):
pick $COMMIT4 four_edits
pick $COMMIT4 # four_edits
(use "git rebase --edit-todo" to view and edit)
You are currently splitting a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
(Once your working directory is clean, run "git rebase --continue")
Expand Down Expand Up @@ -474,10 +474,10 @@ test_expect_success 'status: (amend first edit) second edit and amend' '
cat >expected <<EOF &&
interactive rebase in progress; onto $ONTO
Last commands done (2 commands done):
edit $COMMIT2 two_edits
edit $COMMIT3 three_edits
edit $COMMIT2 # two_edits
edit $COMMIT3 # three_edits
Next command to do (1 remaining command):
pick $COMMIT4 four_edits
pick $COMMIT4 # four_edits
(use "git rebase --edit-todo" to view and edit)
You are currently editing a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
(use "git commit --amend" to amend the current commit)
Expand Down Expand Up @@ -507,10 +507,10 @@ test_expect_success 'status: (split first edit) second edit' '
cat >expected <<EOF &&
interactive rebase in progress; onto $ONTO
Last commands done (2 commands done):
edit $COMMIT2 two_edits
edit $COMMIT3 three_edits
edit $COMMIT2 # two_edits
edit $COMMIT3 # three_edits
Next command to do (1 remaining command):
pick $COMMIT4 four_edits
pick $COMMIT4 # four_edits
(use "git rebase --edit-todo" to view and edit)
You are currently editing a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
(use "git commit --amend" to amend the current commit)
Expand Down Expand Up @@ -541,10 +541,10 @@ test_expect_success 'status: (split first edit) second edit and split' '
cat >expected <<EOF &&
interactive rebase in progress; onto $ONTO
Last commands done (2 commands done):
edit $COMMIT2 two_edits
edit $COMMIT3 three_edits
edit $COMMIT2 # two_edits
edit $COMMIT3 # three_edits
Next command to do (1 remaining command):
pick $COMMIT4 four_edits
pick $COMMIT4 # four_edits
(use "git rebase --edit-todo" to view and edit)
You are currently splitting a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
(Once your working directory is clean, run "git rebase --continue")
Expand Down Expand Up @@ -579,10 +579,10 @@ test_expect_success 'status: (split first edit) second edit and amend' '
cat >expected <<EOF &&
interactive rebase in progress; onto $ONTO
Last commands done (2 commands done):
edit $COMMIT2 two_edits
edit $COMMIT3 three_edits
edit $COMMIT2 # two_edits
edit $COMMIT3 # three_edits
Next command to do (1 remaining command):
pick $COMMIT4 four_edits
pick $COMMIT4 # four_edits
(use "git rebase --edit-todo" to view and edit)
You are currently editing a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
(use "git commit --amend" to amend the current commit)
Expand Down Expand Up @@ -947,11 +947,11 @@ test_expect_success 'status: two commands done with some white lines in done fil
cat >expected <<EOF &&
interactive rebase in progress; onto $ONTO
Last commands done (2 commands done):
pick $COMMIT2 two_commit
pick $COMMIT2 # two_commit
exec exit 15
Next commands to do (2 remaining commands):
pick $COMMIT3 three_commit
pick $COMMIT4 four_commit
pick $COMMIT3 # three_commit
pick $COMMIT4 # four_commit
(use "git rebase --edit-todo" to view and edit)
You are currently editing a commit while rebasing branch '\''several_commits'\'' on '\''$ONTO'\''.
(use "git commit --amend" to amend the current commit)
Expand All @@ -975,12 +975,12 @@ test_expect_success 'status: two remaining commands with some white lines in tod
cat >expected <<EOF &&
interactive rebase in progress; onto $ONTO
Last commands done (3 commands done):
pick $COMMIT2 two_commit
pick $COMMIT2 # two_commit
exec exit 15
(see more in file .git/rebase-merge/done)
Next commands to do (2 remaining commands):
pick $COMMIT3 three_commit
pick $COMMIT4 four_commit
pick $COMMIT3 # three_commit
pick $COMMIT4 # four_commit
(use "git rebase --edit-todo" to view and edit)
You are currently editing a commit while rebasing branch '\''several_commits'\'' on '\''$ONTO'\''.
(use "git commit --amend" to amend the current commit)
Expand All @@ -1000,7 +1000,7 @@ test_expect_success 'status: handle not-yet-started rebase -i gracefully' '
On branch several_commits
No commands done.
Next command to do (1 remaining command):
pick $COMMIT four_commit
pick $COMMIT # four_commit
(use "git rebase --edit-todo" to view and edit)
You are currently editing a commit while rebasing branch '\''several_commits'\'' on '\''$ONTO'\''.
(use "git commit --amend" to amend the current commit)
Expand Down

0 comments on commit f1ae608

Please sign in to comment.