Skip to content

Commit 5d29020

Browse files
committed
sequencer: make it clearer that commit descriptions are just comments
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. Hopefully that leads to them looking a little further and noticing the hints at the bottom to use 'reword' or 'edit' directives. Yes, this change may look funny at first since it hardcodes '#' rather than using comment_line_str. However: * comment_line_str exists to allow disambiguation between lines in a commit message and lines that are instructions to users editing the commit message. No such disambiguation is needed for these comments that occur on the same line after existing directives * the exact "comment" character(s) on regular pick lines used aren't actually important; I could have used anything, including completely random variable length text for each line and it'd work because we ignore everything after 'pick' and the hash. * The whole point of this change is to signal to users that they should NOT be editing any part of the line after the hash (and if they do so, their edits will be ignored), while the whole point of comment_line_str is to allow highly flexible editing. So making it more general by using comment_line_str actually feels counterproductive. * The character for merge directives absolutely must be '#'; that has been deeply hardcoded for a long time (see below), and will break if some other comment character is used instead. In a desire to have pick and merge directives be similar, I use the same comment character for both. * Perhaps merge directives could be fixed to not be inflexible about the comment character used, if someone feels highly motivated, but I think that should be done in a separate follow-on patch. Here are (some of?) the locations where '#' has already been hardcoded for a long time for merges: 1) In check_label_or_ref_arg(): case TODO_LABEL: /* * '#' is not a valid label as the merge command uses it to * separate merge parents from the commit subject. */ 2) In do_merge(): /* * For octopus merges, the arg starts with the list of revisions to be * merged. The list is optionally followed by '#' and the oneline. */ merge_arg_len = oneline_offset = arg_len; for (p = arg; p - arg < arg_len; p += strspn(p, " \t\n")) { if (!*p) break; if (*p == '#' && (!p[1] || isspace(p[1]))) { 3) In label_oid(): if ((buf->len == the_hash_algo->hexsz && !get_oid_hex(label, &dummy)) || (buf->len == 1 && *label == '#') || hashmap_get_from_hash(&state->labels, strihash(label), label)) { /* * If the label already exists, or if the label is a * valid full OID, or the label is a '#' (which we use * as a separator between merge heads and oneline), we * append a dash and a number to make it unique. */ Signed-off-by: Elijah Newren <[email protected]>
1 parent 1a8a497 commit 5d29020

6 files changed

+94
-88
lines changed

sequencer.c

+11-5
Original file line numberDiff line numberDiff line change
@@ -5901,11 +5901,11 @@ static int make_script_with_merges(struct pretty_print_context *pp,
59015901

59025902
/* Create a label from the commit message */
59035903
strbuf_reset(&label_from_message);
5904-
if (skip_prefix(oneline.buf, "Merge ", &p1) &&
5904+
if (skip_prefix(oneline.buf, "# Merge ", &p1) &&
59055905
(p1 = strchr(p1, '\'')) &&
59065906
(p2 = strchr(++p1, '\'')))
59075907
strbuf_add(&label_from_message, p1, p2 - p1);
5908-
else if (skip_prefix(oneline.buf, "Merge pull request ",
5908+
else if (skip_prefix(oneline.buf, "# Merge pull request ",
59095909
&p1) &&
59105910
(p1 = strstr(p1, " from ")))
59115911
strbuf_addstr(&label_from_message, p1 + strlen(" from "));
@@ -5940,7 +5940,7 @@ static int make_script_with_merges(struct pretty_print_context *pp,
59405940

59415941
strbuf_addstr(&buf, label_oid(oid, label, &state));
59425942
}
5943-
strbuf_addf(&buf, " # %s", oneline.buf);
5943+
strbuf_addf(&buf, " %s", oneline.buf);
59445944

59455945
FLEX_ALLOC_STR(entry, string, buf.buf);
59465946
oidcpy(&entry->entry.oid, &commit->object.oid);
@@ -6022,7 +6022,7 @@ static int make_script_with_merges(struct pretty_print_context *pp,
60226022
else {
60236023
strbuf_reset(&oneline);
60246024
pretty_print_commit(pp, commit, &oneline);
6025-
strbuf_addf(out, "%s %s # %s\n",
6025+
strbuf_addf(out, "%s %s %s\n",
60266026
cmd_reset, to, oneline.buf);
60276027
}
60286028
}
@@ -6090,8 +6090,14 @@ int sequencer_make_script(struct repository *r, struct strbuf *out, int argc,
60906090
git_config_get_string("rebase.instructionFormat", &format);
60916091
if (!format || !*format) {
60926092
free(format);
6093-
format = xstrdup("%s");
6093+
format = xstrdup("# %s");
60946094
}
6095+
if (*format != '#') {
6096+
char *temp = format;
6097+
format = xstrfmt("# %s", temp);
6098+
free(temp);
6099+
}
6100+
60956101
get_commit_format(format, &revs);
60966102
free(format);
60976103
pp.fmt = revs.commit_format;

t/t3404-rebase-interactive.sh

+27-27
Original file line numberDiff line numberDiff line change
@@ -1468,7 +1468,7 @@ test_expect_success 'rebase -i respects rebase.missingCommitsCheck = warn' '
14681468
cat >expect <<-EOF &&
14691469
Warning: some commits may have been dropped accidentally.
14701470
Dropped commits (newer to older):
1471-
- $(git rev-list --pretty=oneline --abbrev-commit -1 primary)
1471+
- $(git log --format="%h # %s" -1 primary)
14721472
To avoid this message, use "drop" to explicitly remove a commit.
14731473
EOF
14741474
test_config rebase.missingCommitsCheck warn &&
@@ -1486,8 +1486,8 @@ test_expect_success 'rebase -i respects rebase.missingCommitsCheck = error' '
14861486
cat >expect <<-EOF &&
14871487
Warning: some commits may have been dropped accidentally.
14881488
Dropped commits (newer to older):
1489-
- $(git rev-list --pretty=oneline --abbrev-commit -1 primary)
1490-
- $(git rev-list --pretty=oneline --abbrev-commit -1 primary~2)
1489+
- $(git log --format="%h # %s" -1 primary)
1490+
- $(git log --format="%h # %s" -1 primary~2)
14911491
To avoid this message, use "drop" to explicitly remove a commit.
14921492
14931493
Use '\''git config rebase.missingCommitsCheck'\'' to change the level of warnings.
@@ -1530,11 +1530,11 @@ test_expect_success 'rebase --edit-todo respects rebase.missingCommitsCheck = ig
15301530
test_expect_success 'rebase --edit-todo respects rebase.missingCommitsCheck = warn' '
15311531
cat >expect <<-EOF &&
15321532
error: invalid command '\''pickled'\''
1533-
error: invalid line 1: pickled $(git rev-list --pretty=oneline --abbrev-commit -1 primary~4)
1533+
error: invalid line 1: pickled $(git log --format="%h # %s" -1 primary~4)
15341534
Warning: some commits may have been dropped accidentally.
15351535
Dropped commits (newer to older):
1536-
- $(git rev-list --pretty=oneline --abbrev-commit -1 primary)
1537-
- $(git rev-list --pretty=oneline --abbrev-commit -1 primary~4)
1536+
- $(git log --format="%h # %s" -1 primary)
1537+
- $(git log --format="%h # %s" -1 primary~4)
15381538
To avoid this message, use "drop" to explicitly remove a commit.
15391539
EOF
15401540
head -n5 expect >expect.2 &&
@@ -1565,11 +1565,11 @@ test_expect_success 'rebase --edit-todo respects rebase.missingCommitsCheck = wa
15651565
test_expect_success 'rebase --edit-todo respects rebase.missingCommitsCheck = error' '
15661566
cat >expect <<-EOF &&
15671567
error: invalid command '\''pickled'\''
1568-
error: invalid line 1: pickled $(git rev-list --pretty=oneline --abbrev-commit -1 primary~4)
1568+
error: invalid line 1: pickled $(git log --format="%h # %s" -1 primary~4)
15691569
Warning: some commits may have been dropped accidentally.
15701570
Dropped commits (newer to older):
1571-
- $(git rev-list --pretty=oneline --abbrev-commit -1 primary)
1572-
- $(git rev-list --pretty=oneline --abbrev-commit -1 primary~4)
1571+
- $(git log --format="%h # %s" -1 primary)
1572+
- $(git log --format="%h # %s" -1 primary~4)
15731573
To avoid this message, use "drop" to explicitly remove a commit.
15741574
15751575
Use '\''git config rebase.missingCommitsCheck'\'' to change the level of warnings.
@@ -1642,11 +1642,11 @@ test_expect_success 'respects rebase.abbreviateCommands with fixup, squash and e
16421642
test_commit "fixup! first" file2.txt "first line again" first_fixup &&
16431643
test_commit "squash! second" file1.txt "another line here" second_squash &&
16441644
cat >expected <<-EOF &&
1645-
p $(git rev-list --abbrev-commit -1 first) first
1646-
f $(git rev-list --abbrev-commit -1 first_fixup) fixup! first
1645+
p $(git rev-list --abbrev-commit -1 first) # first
1646+
f $(git rev-list --abbrev-commit -1 first_fixup) # fixup! first
16471647
x git show HEAD
1648-
p $(git rev-list --abbrev-commit -1 second) second
1649-
s $(git rev-list --abbrev-commit -1 second_squash) squash! second
1648+
p $(git rev-list --abbrev-commit -1 second) # second
1649+
s $(git rev-list --abbrev-commit -1 second_squash) # squash! second
16501650
x git show HEAD
16511651
EOF
16521652
git checkout abbrevcmd &&
@@ -1665,7 +1665,7 @@ test_expect_success 'static check of bad command' '
16651665
set_fake_editor &&
16661666
test_must_fail env FAKE_LINES="1 2 3 bad 4 5" \
16671667
git rebase -i --root 2>actual &&
1668-
test_grep "pickled $(git rev-list --oneline -1 primary~1)" \
1668+
test_grep "pickled $(git log --format="%h # %s" -1 primary~1)" \
16691669
actual &&
16701670
test_grep "You can fix this with .git rebase --edit-todo.." \
16711671
actual &&
@@ -1865,15 +1865,15 @@ test_expect_success '--update-refs adds label and update-ref commands' '
18651865
set_cat_todo_editor &&
18661866
18671867
cat >expect <<-EOF &&
1868-
pick $(git log -1 --format=%h J) J
1869-
fixup $(git log -1 --format=%h update-refs) fixup! J # empty
1868+
pick $(git log -1 --format=%h J) # J
1869+
fixup $(git log -1 --format=%h update-refs) # fixup! J # empty
18701870
update-ref refs/heads/second
18711871
update-ref refs/heads/first
1872-
pick $(git log -1 --format=%h K) K
1873-
pick $(git log -1 --format=%h L) L
1874-
fixup $(git log -1 --format=%h is-not-reordered) fixup! L # empty
1872+
pick $(git log -1 --format=%h K) # K
1873+
pick $(git log -1 --format=%h L) # L
1874+
fixup $(git log -1 --format=%h is-not-reordered) # fixup! L # empty
18751875
update-ref refs/heads/third
1876-
pick $(git log -1 --format=%h M) M
1876+
pick $(git log -1 --format=%h M) # M
18771877
update-ref refs/heads/no-conflict-branch
18781878
update-ref refs/heads/is-not-reordered
18791879
update-ref refs/heads/shared-tip
@@ -1905,19 +1905,19 @@ test_expect_success '--update-refs adds commands with --rebase-merges' '
19051905
cat >expect <<-EOF &&
19061906
label onto
19071907
reset onto
1908-
pick $(git log -1 --format=%h branch2~1) F
1909-
pick $(git log -1 --format=%h branch2) I
1908+
pick $(git log -1 --format=%h branch2~1) # F
1909+
pick $(git log -1 --format=%h branch2) # I
19101910
update-ref refs/heads/branch2
19111911
label branch2
19121912
reset onto
1913-
pick $(git log -1 --format=%h refs/heads/second) J
1913+
pick $(git log -1 --format=%h refs/heads/second) # J
19141914
update-ref refs/heads/second
19151915
update-ref refs/heads/first
1916-
pick $(git log -1 --format=%h refs/heads/third~1) K
1917-
pick $(git log -1 --format=%h refs/heads/third) L
1918-
fixup $(git log -1 --format=%h update-refs-with-merge) fixup! L # empty
1916+
pick $(git log -1 --format=%h refs/heads/third~1) # K
1917+
pick $(git log -1 --format=%h refs/heads/third) # L
1918+
fixup $(git log -1 --format=%h update-refs-with-merge) # fixup! L # empty
19191919
update-ref refs/heads/third
1920-
pick $(git log -1 --format=%h HEAD~2) M
1920+
pick $(git log -1 --format=%h HEAD~2) # M
19211921
update-ref refs/heads/no-conflict-branch
19221922
merge -C $(git log -1 --format=%h HEAD~1) branch2 # merge
19231923
update-ref refs/heads/merge-branch

t/t3415-rebase-autosquash.sh

+7-7
Original file line numberDiff line numberDiff line change
@@ -257,8 +257,8 @@ test_expect_success 'auto squash of fixup commit that matches branch name which
257257
GIT_SEQUENCE_EDITOR="cat >tmp" git rebase --autosquash -i HEAD^^ &&
258258
sed -ne "/^[^#]/{s/[0-9a-f]\{7,\}/HASH/g;p;}" tmp >actual &&
259259
cat <<-EOF >expect &&
260-
pick HASH second commit
261-
pick HASH fixup! self-cycle # empty
260+
pick HASH # second commit
261+
pick HASH # fixup! self-cycle # empty
262262
EOF
263263
test_cmp expect actual
264264
'
@@ -311,10 +311,10 @@ test_auto_fixup_fixup () {
311311
parent2=$(git rev-parse --short HEAD^^) &&
312312
parent3=$(git rev-parse --short HEAD^^^) &&
313313
cat >expected <<-EOF &&
314-
pick $parent3 first commit
315-
$1 $parent1 $1! first
316-
$1 $head $1! $2! first
317-
pick $parent2 second commit
314+
pick $parent3 # first commit
315+
$1 $parent1 # $1! first
316+
$1 $head # $1! $2! first
317+
pick $parent2 # second commit
318318
EOF
319319
test_cmp expected actual
320320
) &&
@@ -389,7 +389,7 @@ test_expect_success 'autosquash with empty custom instructionFormat' '
389389
set_cat_todo_editor &&
390390
test_must_fail git -c rebase.instructionFormat= \
391391
rebase --autosquash --force-rebase -i HEAD^ >actual &&
392-
git log -1 --format="pick %h %s" >expect &&
392+
git log -1 --format="pick %h # %s" >expect &&
393393
test_cmp expect actual
394394
)
395395
'

t/t3430-rebase-merges.sh

+5-5
Original file line numberDiff line numberDiff line change
@@ -106,18 +106,18 @@ test_expect_success 'generate correct todo list' '
106106
label onto
107107
108108
reset onto
109-
pick $b B
109+
pick $b # B
110110
label first
111111
112112
reset onto
113-
pick $c C
113+
pick $c # C
114114
label branch-point
115-
pick $f F
116-
pick $g G
115+
pick $f # F
116+
pick $g # G
117117
label second
118118
119119
reset branch-point # C
120-
pick $d D
120+
pick $d # D
121121
merge -C $e first # E
122122
merge -C $h second # H
123123

t/t5520-pull.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -813,7 +813,7 @@ test_expect_success 'git pull --rebase does not reapply old patches' '
813813
cd dst &&
814814
test_must_fail git pull --rebase &&
815815
cat .git/rebase-merge/done .git/rebase-merge/git-rebase-todo >work &&
816-
grep -v -e \# -e ^$ work >patches &&
816+
grep -v -e ^\# -e ^$ work >patches &&
817817
test_line_count = 1 patches &&
818818
rm -f work
819819
)

0 commit comments

Comments
 (0)