Merge branch 'kh/sequencer-comment-char'
The sequencer failed to honor core.commentString in some places. * kh/sequencer-comment-char: sequencer: comment commit messages properly sequencer: comment `--reference` subject line properly sequencer: comment checked-out branch properly
This commit is contained in:
24
sequencer.c
24
sequencer.c
@@ -1941,10 +1941,10 @@ static int seen_squash(struct replay_ctx *ctx)
|
||||
|
||||
static void update_comment_bufs(struct strbuf *buf1, struct strbuf *buf2, int n)
|
||||
{
|
||||
strbuf_setlen(buf1, 2);
|
||||
strbuf_setlen(buf1, strlen(comment_line_str) + 1);
|
||||
strbuf_addf(buf1, _(nth_commit_msg_fmt), n);
|
||||
strbuf_addch(buf1, '\n');
|
||||
strbuf_setlen(buf2, 2);
|
||||
strbuf_setlen(buf2, strlen(comment_line_str) + 1);
|
||||
strbuf_addf(buf2, _(skip_nth_commit_msg_fmt), n);
|
||||
strbuf_addch(buf2, '\n');
|
||||
}
|
||||
@@ -1963,8 +1963,12 @@ static void update_squash_message_for_fixup(struct strbuf *msg)
|
||||
size_t orig_msg_len;
|
||||
int i = 1;
|
||||
|
||||
strbuf_addf(&buf1, "# %s\n", _(first_commit_msg_str));
|
||||
strbuf_addf(&buf2, "# %s\n", _(skip_first_commit_msg_str));
|
||||
strbuf_add_commented_lines(&buf1, _(first_commit_msg_str),
|
||||
strlen(_(first_commit_msg_str)),
|
||||
comment_line_str);
|
||||
strbuf_add_commented_lines(&buf2, _(skip_first_commit_msg_str),
|
||||
strlen(_(skip_first_commit_msg_str)),
|
||||
comment_line_str);
|
||||
s = start = orig_msg = strbuf_detach(msg, &orig_msg_len);
|
||||
while (s) {
|
||||
const char *next;
|
||||
@@ -2341,8 +2345,8 @@ static int do_pick_commit(struct repository *r,
|
||||
next = parent;
|
||||
next_label = msg.parent_label;
|
||||
if (opts->commit_use_reference) {
|
||||
strbuf_addstr(&ctx->message,
|
||||
"# *** SAY WHY WE ARE REVERTING ON THE TITLE LINE ***");
|
||||
strbuf_commented_addf(&ctx->message, comment_line_str,
|
||||
"*** SAY WHY WE ARE REVERTING ON THE TITLE LINE ***");
|
||||
} else if (skip_prefix(msg.subject, "Revert \"", &orig_subject) &&
|
||||
/*
|
||||
* We don't touch pre-existing repeated reverts, because
|
||||
@@ -2352,12 +2356,13 @@ static int do_pick_commit(struct repository *r,
|
||||
!starts_with(orig_subject, "Revert \"")) {
|
||||
strbuf_addstr(&ctx->message, "Reapply \"");
|
||||
strbuf_addstr(&ctx->message, orig_subject);
|
||||
strbuf_addstr(&ctx->message, "\n");
|
||||
} else {
|
||||
strbuf_addstr(&ctx->message, "Revert \"");
|
||||
strbuf_addstr(&ctx->message, msg.subject);
|
||||
strbuf_addstr(&ctx->message, "\"");
|
||||
strbuf_addstr(&ctx->message, "\"\n");
|
||||
}
|
||||
strbuf_addstr(&ctx->message, "\n\nThis reverts commit ");
|
||||
strbuf_addstr(&ctx->message, "\nThis reverts commit ");
|
||||
refer_to_commit(opts, &ctx->message, commit);
|
||||
|
||||
if (commit->parents && commit->parents->next) {
|
||||
@@ -6382,7 +6387,8 @@ static int add_decorations_to_list(const struct commit *commit,
|
||||
/* If the branch is checked out, then leave a comment instead. */
|
||||
if ((path = branch_checked_out(decoration->name))) {
|
||||
item->command = TODO_COMMENT;
|
||||
strbuf_addf(ctx->buf, "# Ref %s checked out at '%s'\n",
|
||||
strbuf_commented_addf(ctx->buf, comment_line_str,
|
||||
"Ref %s checked out at '%s'\n",
|
||||
decoration->name, path);
|
||||
} else {
|
||||
struct string_list_item *sti;
|
||||
|
||||
@@ -455,4 +455,23 @@ test_expect_success 'rebase when inside worktree subdirectory' '
|
||||
)
|
||||
'
|
||||
|
||||
test_expect_success 'git rebase --update-ref with core.commentChar and branch on worktree' '
|
||||
test_when_finished git branch -D base topic2 &&
|
||||
test_when_finished git checkout main &&
|
||||
test_when_finished git branch -D wt-topic &&
|
||||
test_when_finished git worktree remove wt-topic &&
|
||||
git checkout main &&
|
||||
git checkout -b base &&
|
||||
git checkout -b topic2 &&
|
||||
test_commit msg2 &&
|
||||
git worktree add wt-topic &&
|
||||
git checkout base &&
|
||||
test_commit msg3 &&
|
||||
git checkout topic2 &&
|
||||
GIT_SEQUENCE_EDITOR="cat >actual" git -c core.commentChar=% \
|
||||
rebase -i --update-refs base &&
|
||||
test_grep "% Ref refs/heads/wt-topic checked out at" actual &&
|
||||
test_grep "% Ref refs/heads/topic2 checked out at" actual
|
||||
'
|
||||
|
||||
test_done
|
||||
|
||||
@@ -126,6 +126,21 @@ test_expect_success 'fixup -C with conflicts gives correct message' '
|
||||
test_cmp expected-author actual-author
|
||||
'
|
||||
|
||||
test_expect_success 'conflicting fixup -C after fixup with custom comment string' '
|
||||
test_config core.commentString COMMENT &&
|
||||
test_when_finished "test_might_fail git rebase --abort" &&
|
||||
git checkout --detach A3 &&
|
||||
test_must_fail env FAKE_LINES="1 fixup 2 fixup_-C 4" git rebase -i A &&
|
||||
echo resolved >A &&
|
||||
git add A &&
|
||||
FAKE_COMMIT_AMEND=edited git rebase --continue &&
|
||||
test_commit_message HEAD <<-\EOF
|
||||
A3
|
||||
|
||||
edited
|
||||
EOF
|
||||
'
|
||||
|
||||
test_expect_success 'skipping fixup -C after fixup gives correct message' '
|
||||
test_when_finished "test_might_fail git rebase --abort" &&
|
||||
git checkout --detach A3 &&
|
||||
|
||||
@@ -227,6 +227,20 @@ test_expect_success 'identification of reverted commit (--reference)' '
|
||||
test_cmp expect actual
|
||||
'
|
||||
|
||||
test_expect_success 'git revert --reference with core.commentChar' '
|
||||
test_when_finished "git reset --hard to-ident" &&
|
||||
git checkout --detach to-ident &&
|
||||
GIT_EDITOR="head -n4 >actual" git -c core.commentChar=% revert \
|
||||
--edit --reference HEAD &&
|
||||
cat <<-EOF >expect &&
|
||||
% *** SAY WHY WE ARE REVERTING ON THE TITLE LINE ***
|
||||
|
||||
This reverts commit $(git show -s --pretty=reference HEAD^).
|
||||
|
||||
EOF
|
||||
test_cmp expect actual
|
||||
'
|
||||
|
||||
test_expect_success 'identification of reverted commit (revert.reference)' '
|
||||
git checkout --detach to-ident &&
|
||||
git -c revert.reference=true revert --no-edit HEAD &&
|
||||
|
||||
Reference in New Issue
Block a user