Skip to content

Commit

Permalink
sequencer: reencode squashing commit's message
Browse files Browse the repository at this point in the history
On fixup/squash-ing rebase, git will create new commit in
i18n.commitencoding, reencode the commit message to that said encode.

Signed-off-by: Doan Tran Cong Danh <congdanhqx@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
sgn authored and gitster committed Nov 11, 2019
1 parent 019a9d8 commit b375744
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
8 changes: 5 additions & 3 deletions sequencer.c
Original file line number Diff line number Diff line change
Expand Up @@ -1576,6 +1576,7 @@ static int update_squash_messages(struct repository *r,
struct strbuf buf = STRBUF_INIT;
int res;
const char *message, *body;
const char *encoding = get_commit_output_encoding();

if (opts->current_fixup_count > 0) {
struct strbuf header = STRBUF_INIT;
Expand All @@ -1602,7 +1603,7 @@ static int update_squash_messages(struct repository *r,
return error(_("need a HEAD to fixup"));
if (!(head_commit = lookup_commit_reference(r, &head)))
return error(_("could not read HEAD"));
if (!(head_message = get_commit_buffer(head_commit, NULL)))
if (!(head_message = logmsg_reencode(head_commit, NULL, encoding)))
return error(_("could not read HEAD's commit message"));

find_commit_subject(head_message, &body);
Expand All @@ -1623,7 +1624,7 @@ static int update_squash_messages(struct repository *r,
unuse_commit_buffer(head_commit, head_message);
}

if (!(message = get_commit_buffer(commit, NULL)))
if (!(message = logmsg_reencode(commit, NULL, encoding)))
return error(_("could not read commit message of %s"),
oid_to_hex(&commit->object.oid));
find_commit_subject(message, &body);
Expand Down Expand Up @@ -4154,9 +4155,10 @@ static int commit_staged_changes(struct repository *r,
*/
struct commit *commit;
const char *path = rebase_path_squash_msg();
const char *encoding = get_commit_output_encoding();

if (parse_head(r, &commit) ||
!(p = get_commit_buffer(commit, NULL)) ||
!(p = logmsg_reencode(commit, NULL, encoding)) ||
write_message(p, strlen(p), path, 0)) {
unuse_commit_buffer(commit, p);
return error(_("could not write file: "
Expand Down
10 changes: 9 additions & 1 deletion t/t3900-i18n-commit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,15 @@ test_commit_autosquash_multi_encoding () {
git commit -a --$flag HEAD^ &&
git rebase --autosquash -i HEAD^^^ &&
git rev-list HEAD >actual &&
test_line_count = 3 actual
test_line_count = 3 actual &&
iconv -f $old -t UTF-8 "$TEST_DIRECTORY"/t3900/$msg >expect &&
if test $flag = squash; then
subject="$(head -1 expect)" &&
printf "\nsquash! %s\n" "$subject" >>expect
fi &&
git cat-file commit HEAD^ >raw &&
(sed "1,/^$/d" raw | iconv -f $new -t utf-8) >actual &&
test_cmp expect actual
'
}

Expand Down

0 comments on commit b375744

Please sign in to comment.