diff mbox series

[v5,7/9] sequencer: reencode old merge-commit message

Message ID def9adf97ecb946a2cbde94b3eed742c17eb46c2.1573205699.git.congdanhqx@gmail.com (mailing list archive)
State New, archived
Headers show
Series Improve odd encoding integration | expand

Commit Message

Đoàn Trần Công Danh Nov. 8, 2019, 9:43 a.m. UTC
During rebasing, old merge's message (encoded in old encoding)
will be used as message for new merge commit (created by rebase).

In case of the value of i18n.commitencoding has been changed after the
old merge time. We will receive an unusable message for this new merge.

Correct it.

This change also notice a breakage with git-rebase label system.

Signed-off-by: Doan Tran Cong Danh <congdanhqx@gmail.com>
---

Notes:
	eucJP.txt is copied from t3900

 sequencer.c            |   3 ++-
 t/t3433-rebase-i18n.sh |  57 +++++++++++++++++++++++++++++++++++++++++
 t/t3433/eucJP.txt      | Bin 0 -> 68 bytes
 3 files changed, 59 insertions(+), 1 deletion(-)
 create mode 100755 t/t3433-rebase-i18n.sh
 create mode 100644 t/t3433/eucJP.txt

GIT binary patch
literal 68
zcmZ2-e#x69mzLaKa+Ql~$@V43mMmHFddayZYZfkovW_oY%ys|3$+JKuZ<btN@@mOl
SAboGi<s}<{?6*s90HpysEiSzP

literal 0
HcmV?d00001
diff mbox series

Patch

diff --git a/sequencer.c b/sequencer.c
index 833a928929..d735d09f98 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -3374,7 +3374,8 @@  static int do_merge(struct repository *r,
 	}
 
 	if (commit) {
-		const char *message = get_commit_buffer(commit, NULL);
+		const char *encoding = get_commit_output_encoding();
+		const char *message = logmsg_reencode(commit, NULL, encoding);
 		const char *body;
 		int len;
 
diff --git a/t/t3433-rebase-i18n.sh b/t/t3433-rebase-i18n.sh
new file mode 100755
index 0000000000..bff5a68d25
--- /dev/null
+++ b/t/t3433-rebase-i18n.sh
@@ -0,0 +1,57 @@ 
+#!/bin/sh
+#
+# Copyright (c) 2019 Doan Tran Cong Danh
+#
+
+test_description='rebase with changing encoding
+
+Initial setup:
+
+1 - 2              master
+ \
+  3 - 4            first
+   \
+    5 - 6          second
+'
+
+. ./test-lib.sh
+
+compare_msg () {
+	iconv -f "$2" -t "$3" "$TEST_DIRECTORY/t3433/$1" >expect &&
+	git cat-file commit HEAD >raw &&
+	sed "1,/^$/d" raw >actual &&
+	test_cmp expect actual
+}
+
+test_expect_success setup '
+	test_commit one &&
+	git branch first &&
+	test_commit two &&
+	git switch first &&
+	test_commit three &&
+	git branch second &&
+	test_commit four &&
+	git switch second &&
+	test_commit five &&
+	test_commit six
+'
+
+test_expect_success 'rebase --rebase-merges update encoding eucJP to UTF-8' '
+	git switch -c merge-eucJP-UTF-8 first &&
+	git config i18n.commitencoding eucJP &&
+	git merge -F "$TEST_DIRECTORY/t3433/eucJP.txt" second &&
+	git config i18n.commitencoding UTF-8 &&
+	git rebase --rebase-merges master &&
+	compare_msg eucJP.txt eucJP UTF-8
+'
+
+test_expect_failure 'rebase --rebase-merges update encoding eucJP to ISO-2022-JP' '
+	git switch -c merge-eucJP-ISO-2022-JP first &&
+	git config i18n.commitencoding eucJP &&
+	git merge -F "$TEST_DIRECTORY/t3433/eucJP.txt" second &&
+	git config i18n.commitencoding ISO-2022-JP &&
+	git rebase --rebase-merges master &&
+	compare_msg eucJP.txt eucJP ISO-2022-JP
+'
+
+test_done
diff --git a/t/t3433/eucJP.txt b/t/t3433/eucJP.txt
new file mode 100644
index 0000000000000000000000000000000000000000..546f2aac01b67e39d19de601f5586097b34a8325