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 git cat-file commit HEAD >raw &&
31 sed "1,/^$/d" raw >actual &&
32 test_cmp expect actual
33 }
34
35 test_expect_success setup '
36 test_commit one &&
37 git branch first &&
38 test_commit two &&
39 git switch first &&
40 test_commit three &&
41 git branch second &&
42 test_commit four &&
43 git switch second &&
44 test_commit five &&
45 test_commit six
46 '
47
48 test_expect_success 'rebase --rebase-merges update encoding eucJP to UTF-8' '
49 git switch -c merge-eucJP-UTF-8 first &&
50 git config i18n.commitencoding eucJP &&
51 git merge -F "$TEST_DIRECTORY/t3434/eucJP.txt" second &&
52 git config i18n.commitencoding UTF-8 &&
53 git rebase --rebase-merges main &&
54 compare_msg eucJP.txt eucJP UTF-8
55 '
56
57 test_expect_success 'rebase --rebase-merges update encoding eucJP to ISO-2022-JP' '
58 git switch -c merge-eucJP-ISO-2022-JP first &&
59 git config i18n.commitencoding eucJP &&
60 git merge -F "$TEST_DIRECTORY/t3434/eucJP.txt" second &&
61 git config i18n.commitencoding ISO-2022-JP &&
62 git rebase --rebase-merges main &&
63 compare_msg eucJP.txt eucJP ISO-2022-JP
64 '
65
66 test_rebase_continue_update_encode () {
67 old=$1
68 new=$2
69 msgfile=$3
70 test_expect_success "rebase --continue update from $old to $new" '
71 (git rebase --abort || : abort current git-rebase failure) &&
72 git switch -c conflict-$old-$new one &&
73 echo for-conflict >two.t &&
74 git add two.t &&
75 git config i18n.commitencoding $old &&
76 git commit -F "$TEST_DIRECTORY/t3434/$msgfile" &&
77 git config i18n.commitencoding $new &&
78 test_must_fail git rebase -m main &&
79 test -f .git/rebase-merge/message &&
80 git stripspace -s <.git/rebase-merge/message >two.t &&
81 git add two.t &&
82 git rebase --continue &&
83 compare_msg $msgfile $old $new &&
84 : git-commit assume invalid utf-8 is latin1 &&
85 test_cmp expect two.t
86 '
87 }
88
89 test_rebase_continue_update_encode ISO-8859-1 UTF-8 ISO8859-1.txt
90 test_rebase_continue_update_encode eucJP UTF-8 eucJP.txt
91 test_rebase_continue_update_encode eucJP ISO-2022-JP eucJP.txt
92
93 test_done