Raw
1 #!/bin/sh
2 #
3 # Copyright (c) 2019 Doan Tran Cong Danh
4 #
5
6 test_description='rebase with changing encoding
7
8 Initial setup:
9
10 1 - 2 main
11 \
12 3 - 4 first
13 \
14 5 - 6 second
15 '
16
17 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
18 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
19
20 . ./test-lib.sh
21
22 if ! test_have_prereq ICONV
23 then
24 skip_all='skipping rebase i18n tests; iconv not available'
25 test_done
26 fi
27
28 compare_msg () {
29 iconv -f "$2" -t "$3" "$TEST_DIRECTORY/t3434/$1" >expect &&
30 commit_body HEAD >actual &&
31 test_cmp expect actual
32 }
33
34 test_expect_success setup '
35 test_commit one &&
36 git branch first &&
37 test_commit two &&
38 git switch first &&
39 test_commit three &&
40 git branch second &&
41 test_commit four &&
42 git switch second &&
43 test_commit five &&
44 test_commit six
45 '
46
47 test_expect_success 'rebase --rebase-merges update encoding eucJP to UTF-8' '
48 git switch -c merge-eucJP-UTF-8 first &&
49 git config i18n.commitencoding eucJP &&
50 git merge -F "$TEST_DIRECTORY/t3434/eucJP.txt" second &&
51 git config i18n.commitencoding UTF-8 &&
52 git rebase --rebase-merges main &&
53 compare_msg eucJP.txt eucJP UTF-8
54 '
55
56 test_expect_success 'rebase --rebase-merges update encoding eucJP to ISO-2022-JP' '
57 git switch -c merge-eucJP-ISO-2022-JP first &&
58 git config i18n.commitencoding eucJP &&
59 git merge -F "$TEST_DIRECTORY/t3434/eucJP.txt" second &&
60 git config i18n.commitencoding ISO-2022-JP &&
61 git rebase --rebase-merges main &&
62 compare_msg eucJP.txt eucJP ISO-2022-JP
63 '
64
65 test_rebase_continue_update_encode () {
66 old=$1
67 new=$2
68 msgfile=$3
69 test_expect_success "rebase --continue update from $old to $new" '
70 (git rebase --abort || : abort current git-rebase failure) &&
71 git switch -c conflict-$old-$new one &&
72 echo for-conflict >two.t &&
73 git add two.t &&
74 git config i18n.commitencoding $old &&
75 git commit -F "$TEST_DIRECTORY/t3434/$msgfile" &&
76 git config i18n.commitencoding $new &&
77 test_must_fail git rebase -m main &&
78 test -f .git/rebase-merge/message &&
79 git stripspace -s <.git/rebase-merge/message >two.t &&
80 git add two.t &&
81 git rebase --continue &&
82 compare_msg $msgfile $old $new &&
83 : git-commit assume invalid utf-8 is latin1 &&
84 test_cmp expect two.t
85 '
86 }
87
88 test_rebase_continue_update_encode ISO-8859-1 UTF-8 ISO8859-1.txt
89 test_rebase_continue_update_encode eucJP UTF-8 eucJP.txt
90 test_rebase_continue_update_encode eucJP ISO-2022-JP eucJP.txt
91
92 test_done