3 test_description
='Test ref-filter and pretty APIs for commit and tag messages using CRLF'
10 cat >.crlf-orig-
$branch.txt
&&
11 cat .crlf-orig-
$branch.txt | append_cr
>.crlf-message-
$branch.txt
&&
12 grep 'Subject' .crlf-orig-
$branch.txt |
tr '\n' ' ' |
sed 's/[ ]*$//' |
tr -d '\n' >.crlf-subject-
$branch.txt
&&
13 grep 'Body' .crlf-message-
$branch.txt
>.crlf-body-
$branch.txt || true
&&
14 LIB_CRLF_BRANCHES
="${LIB_CRLF_BRANCHES} ${branch}" &&
16 hash=$
(git commit-tree HEAD^
{tree
} -p HEAD
-F .crlf-message-
${branch}.txt
) &&
17 git branch
${branch} ${hash} &&
18 git tag tag-
${branch} ${branch} -F .crlf-message-${branch}.txt
--cleanup=verbatim
22 create_crlf_ref crlf
<<-\EOF &&
28 create_crlf_ref crlf-empty-lines-after-subject <<-\
EOF &&
35 create_crlf_ref crlf-two-line-subject <<-\EOF &&
42 create_crlf_ref crlf-two-line-subject-no-body <<-\EOF &&
46 create_crlf_ref crlf-two-line-subject-no-body-trailing-newline <<-\EOF
53 test_crlf_subject_body_and_contents() {
54 command_and_args="$@" &&
56 if test ${command} = "branch" || test ${command} = "for-each-ref" || test ${command} = "tag"
58 atoms="(contents:subject) (contents:body) (contents)"
59 elif test ${command} = "log" || test ${command} = "show"
63 files="subject body message" &&
64 while test -n "${atoms}"
66 set ${atoms} && atom=$1 && shift && atoms="$*" &&
67 set ${files} && file=$1 && shift && files="$*" &&
68 test_expect_success "${command}: --format='%${atom}' works with messages using CRLF" "
70 for ref in ${LIB_CRLF_BRANCHES}
72 cat .crlf-${file}-\"\
${ref}\".txt
>>expect
&&
73 printf \"\n\" >>expect ||
return 1
75 git
$command_and_args --format=\"%${atom}\" >actual
&&
76 test_cmp expect actual
82 test_expect_success 'Setup refs with commit and tag messages using CRLF' '
87 test_expect_success 'branch: --verbose works with messages using CRLF' '
89 for branch in $LIB_CRLF_BRANCHES
91 printf " " >>expect &&
92 cat .crlf-subject-${branch}.txt >>expect &&
93 printf "\n" >>expect || return 1
96 # Remove first two columns, and the line for the currently checked out branch
97 current=$(git branch --show-current) &&
98 grep -v $current <tmp | awk "{\
$1=\
$2=\"\"}1" >actual &&
99 test_cmp expect actual
102 test_crlf_subject_body_and_contents branch --list crlf*
104 test_crlf_subject_body_and_contents tag --list tag-crlf*
106 test_crlf_subject_body_and_contents for-each-ref refs/heads/crlf*
108 test_expect_success 'log: --oneline works with messages using CRLF' '
109 for branch in $LIB_CRLF_BRANCHES
111 cat .crlf-subject-${branch}.txt >expect &&
112 printf "\n" >>expect &&
113 git log --oneline -1 ${branch} >tmp-branch &&
114 git log --oneline -1 tag-${branch} >tmp-tag &&
115 cut -d" " -f2- <tmp-branch >actual-branch &&
116 cut -d" " -f2- <tmp-tag >actual-tag &&
117 test_cmp expect actual-branch &&
118 test_cmp expect actual-tag || return 1
122 test_crlf_subject_body_and_contents log --all --reverse --grep Subject
124 test_crlf_subject_body_and_contents show $LIB_CRLF_BRANCHES