@matheusbsbs / matheus-bagliano / commits / b375744274
Fork 0

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>

Doan Tran Cong Danh committed Nov 8, 2019 at 16:43 UTC b375744274113889c85bee69445375ce51e96648
2 files changed +14 -4
sequencer.c
+5 -3
@@ -1576,6 +1576,7 @@ static int update_squash_messages(struct repository *r,
1576 struct strbuf buf = STRBUF_INIT;
1577 int res;
1578 const char *message, *body;
1579 + const char *encoding = get_commit_output_encoding();
1580
1581 if (opts->current_fixup_count > 0) {
1582 struct strbuf header = STRBUF_INIT;
@@ -1602,7 +1603,7 @@ static int update_squash_messages(struct repository *r,
1603 return error(_("need a HEAD to fixup"));
1604 if (!(head_commit = lookup_commit_reference(r, &head)))
1605 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)))
1607 return error(_("could not read HEAD's commit message"));
1608
1609 find_commit_subject(head_message, &body);
@@ -1623,7 +1624,7 @@ static int update_squash_messages(struct repository *r,
1624 unuse_commit_buffer(head_commit, head_message);
1625 }
1626
1626 - if (!(message = get_commit_buffer(commit, NULL)))
1627 + if (!(message = logmsg_reencode(commit, NULL, encoding)))
1628 return error(_("could not read commit message of %s"),
1629 oid_to_hex(&commit->object.oid));
1630 find_commit_subject(message, &body);
@@ -4154,9 +4155,10 @@ static int commit_staged_changes(struct repository *r,
4155 */
4156 struct commit *commit;
4157 const char *path = rebase_path_squash_msg();
4158 + const char *encoding = get_commit_output_encoding();
4159
4160 if (parse_head(r, &commit) ||
4159 - !(p = get_commit_buffer(commit, NULL)) ||
4161 + !(p = logmsg_reencode(commit, NULL, encoding)) ||
4162 write_message(p, strlen(p), path, 0)) {
4163 unuse_commit_buffer(commit, p);
4164 return error(_("could not write file: "
t/t3900-i18n-commit.sh
+9 -1
@@ -224,7 +224,15 @@ test_commit_autosquash_multi_encoding () {
224 git commit -a --$flag HEAD^ &&
225 git rebase --autosquash -i HEAD^^^ &&
226 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
236 '
237 }
238