Skip to content

Commit b375744

Browse files
sgngitster
authored andcommitted
sequencer: reencode squashing commit's message
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>
1 parent 019a9d8 commit b375744

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

sequencer.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1576,6 +1576,7 @@ static int update_squash_messages(struct repository *r,
15761576
struct strbuf buf = STRBUF_INIT;
15771577
int res;
15781578
const char *message, *body;
1579+
const char *encoding = get_commit_output_encoding();
15791580

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

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

1626-
if (!(message = get_commit_buffer(commit, NULL)))
1627+
if (!(message = logmsg_reencode(commit, NULL, encoding)))
16271628
return error(_("could not read commit message of %s"),
16281629
oid_to_hex(&commit->object.oid));
16291630
find_commit_subject(message, &body);
@@ -4154,9 +4155,10 @@ static int commit_staged_changes(struct repository *r,
41544155
*/
41554156
struct commit *commit;
41564157
const char *path = rebase_path_squash_msg();
4158+
const char *encoding = get_commit_output_encoding();
41574159

41584160
if (parse_head(r, &commit) ||
4159-
!(p = get_commit_buffer(commit, NULL)) ||
4161+
!(p = logmsg_reencode(commit, NULL, encoding)) ||
41604162
write_message(p, strlen(p), path, 0)) {
41614163
unuse_commit_buffer(commit, p);
41624164
return error(_("could not write file: "

t/t3900-i18n-commit.sh

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,15 @@ test_commit_autosquash_multi_encoding () {
224224
git commit -a --$flag HEAD^ &&
225225
git rebase --autosquash -i HEAD^^^ &&
226226
git rev-list HEAD >actual &&
227-
test_line_count = 3 actual
227+
test_line_count = 3 actual &&
228+
iconv -f $old -t UTF-8 "$TEST_DIRECTORY"/t3900/$msg >expect &&
229+
if test $flag = squash; then
230+
subject="$(head -1 expect)" &&
231+
printf "\nsquash! %s\n" "$subject" >>expect
232+
fi &&
233+
git cat-file commit HEAD^ >raw &&
234+
(sed "1,/^$/d" raw | iconv -f $new -t utf-8) >actual &&
235+
test_cmp expect actual
228236
'
229237
}
230238

0 commit comments

Comments
 (0)