]>
Commit | Line | Data |
---|---|---|
9f75ce3d PB |
1 | #!/bin/sh |
2 | ||
3 | test_description='Test ref-filter and pretty APIs for commit and tag messages using CRLF' | |
055e57b7 ÆAB |
4 | |
5 | TEST_PASSES_SANITIZE_LEAK=true | |
9f75ce3d PB |
6 | . ./test-lib.sh |
7 | ||
8 | LIB_CRLF_BRANCHES="" | |
9 | ||
10 | create_crlf_ref () { | |
11 | branch="$1" && | |
12 | cat >.crlf-orig-$branch.txt && | |
13 | cat .crlf-orig-$branch.txt | append_cr >.crlf-message-$branch.txt && | |
14 | grep 'Subject' .crlf-orig-$branch.txt | tr '\n' ' ' | sed 's/[ ]*$//' | tr -d '\n' >.crlf-subject-$branch.txt && | |
86325d36 | 15 | grep 'Body' .crlf-orig-$branch.txt | append_cr >.crlf-body-$branch.txt && |
9f75ce3d PB |
16 | LIB_CRLF_BRANCHES="${LIB_CRLF_BRANCHES} ${branch}" && |
17 | test_tick && | |
18 | hash=$(git commit-tree HEAD^{tree} -p HEAD -F .crlf-message-${branch}.txt) && | |
19 | git branch ${branch} ${hash} && | |
20 | git tag tag-${branch} ${branch} -F .crlf-message-${branch}.txt --cleanup=verbatim | |
21 | } | |
22 | ||
23 | create_crlf_refs () { | |
24 | create_crlf_ref crlf <<-\EOF && | |
25 | Subject first line | |
26 | ||
27 | Body first line | |
28 | Body second line | |
29 | EOF | |
30 | create_crlf_ref crlf-empty-lines-after-subject <<-\EOF && | |
31 | Subject first line | |
32 | ||
33 | ||
34 | Body first line | |
35 | Body second line | |
36 | EOF | |
37 | create_crlf_ref crlf-two-line-subject <<-\EOF && | |
38 | Subject first line | |
39 | Subject second line | |
40 | ||
41 | Body first line | |
42 | Body second line | |
43 | EOF | |
44 | create_crlf_ref crlf-two-line-subject-no-body <<-\EOF && | |
45 | Subject first line | |
46 | Subject second line | |
47 | EOF | |
48 | create_crlf_ref crlf-two-line-subject-no-body-trailing-newline <<-\EOF | |
49 | Subject first line | |
50 | Subject second line | |
51 | ||
52 | EOF | |
53 | } | |
54 | ||
55 | test_crlf_subject_body_and_contents() { | |
56 | command_and_args="$@" && | |
57 | command=$1 && | |
58 | if test ${command} = "branch" || test ${command} = "for-each-ref" || test ${command} = "tag" | |
59 | then | |
60 | atoms="(contents:subject) (contents:body) (contents)" | |
61 | elif test ${command} = "log" || test ${command} = "show" | |
62 | then | |
63 | atoms="s b B" | |
64 | fi && | |
65 | files="subject body message" && | |
66 | while test -n "${atoms}" | |
67 | do | |
68 | set ${atoms} && atom=$1 && shift && atoms="$*" && | |
52ff891c | 69 | set ${files} && file=$1 && shift && files="$*" && |
9f75ce3d PB |
70 | test_expect_success "${command}: --format='%${atom}' works with messages using CRLF" " |
71 | rm -f expect && | |
72 | for ref in ${LIB_CRLF_BRANCHES} | |
73 | do | |
74 | cat .crlf-${file}-\"\${ref}\".txt >>expect && | |
db5875aa | 75 | printf \"\n\" >>expect || return 1 |
9f75ce3d PB |
76 | done && |
77 | git $command_and_args --format=\"%${atom}\" >actual && | |
78 | test_cmp expect actual | |
79 | " | |
80 | done | |
81 | } | |
82 | ||
83 | ||
84 | test_expect_success 'Setup refs with commit and tag messages using CRLF' ' | |
85 | test_commit inital && | |
86 | create_crlf_refs | |
87 | ' | |
88 | ||
89 | test_expect_success 'branch: --verbose works with messages using CRLF' ' | |
90 | rm -f expect && | |
91 | for branch in $LIB_CRLF_BRANCHES | |
92 | do | |
93 | printf " " >>expect && | |
94 | cat .crlf-subject-${branch}.txt >>expect && | |
db5875aa | 95 | printf "\n" >>expect || return 1 |
9f75ce3d PB |
96 | done && |
97 | git branch -v >tmp && | |
98 | # Remove first two columns, and the line for the currently checked out branch | |
99 | current=$(git branch --show-current) && | |
100 | grep -v $current <tmp | awk "{\$1=\$2=\"\"}1" >actual && | |
101 | test_cmp expect actual | |
102 | ' | |
103 | ||
104 | test_crlf_subject_body_and_contents branch --list crlf* | |
105 | ||
106 | test_crlf_subject_body_and_contents tag --list tag-crlf* | |
107 | ||
108 | test_crlf_subject_body_and_contents for-each-ref refs/heads/crlf* | |
109 | ||
e2f89586 PB |
110 | test_expect_success 'log: --oneline works with messages using CRLF' ' |
111 | for branch in $LIB_CRLF_BRANCHES | |
112 | do | |
113 | cat .crlf-subject-${branch}.txt >expect && | |
114 | printf "\n" >>expect && | |
115 | git log --oneline -1 ${branch} >tmp-branch && | |
116 | git log --oneline -1 tag-${branch} >tmp-tag && | |
117 | cut -d" " -f2- <tmp-branch >actual-branch && | |
118 | cut -d" " -f2- <tmp-tag >actual-tag && | |
119 | test_cmp expect actual-branch && | |
120 | test_cmp expect actual-tag || return 1 | |
121 | done | |
122 | ' | |
123 | ||
124 | test_crlf_subject_body_and_contents log --all --reverse --grep Subject | |
125 | ||
126 | test_crlf_subject_body_and_contents show $LIB_CRLF_BRANCHES | |
127 | ||
9f75ce3d | 128 | test_done |