old mode 100644
new mode 100755
@@ -1,16 +1,17 @@
-# Setup refs with commit and tag messages containing CRLF
+#!/bin/sh
+
+test_description='Test ref-filter and pretty APIs for commit and tag messages using CRLF'
+. ./test-lib.sh
LIB_CRLF_BRANCHES=""
create_crlf_ref () {
- message="$1" &&
- subject="$2" &&
- body="$3" &&
- branch="$4" &&
- printf "${message}" >.crlf-message-${branch}.txt &&
- printf "${subject}" >.crlf-subject-${branch}.txt &&
- printf "${body}" >.crlf-body-${branch}.txt &&
- LIB_CRLF_BRANCHES="${LIB_CRLF_BRANCHES} ${branch}"
+ branch="$1" &&
+ cat >.crlf-orig-$branch.txt &&
+ cat .crlf-orig-$branch.txt | append_cr >.crlf-message-$branch.txt &&
+ grep 'Subject' .crlf-orig-$branch.txt | tr '\n' ' ' | sed 's/[ ]*$//' | tr -d '\n' >.crlf-subject-$branch.txt &&
+ grep 'Body' .crlf-message-$branch.txt >.crlf-body-$branch.txt || true &&
+ LIB_CRLF_BRANCHES="${LIB_CRLF_BRANCHES} ${branch}" &&
test_tick &&
hash=$(git commit-tree HEAD^{tree} -p HEAD -F .crlf-message-${branch}.txt) &&
git branch ${branch} ${hash} &&
@@ -18,73 +19,108 @@ create_crlf_ref () {
}
create_crlf_refs () {
- message="Subject first line\r\n\r\nBody first line\r\nBody second line\r\n" &&
- body="Body first line\r\nBody second line\r\n" &&
- subject="Subject first line" &&
- branch="crlf" &&
- create_crlf_ref "${message}" "${subject}" "${body}" "${branch}" &&
- message="Subject first line\r\n\r\n\r\nBody first line\r\nBody second line\r\n" &&
- branch="crlf-empty-lines-after-subject" &&
- create_crlf_ref "${message}" "${subject}" "${body}" "${branch}" &&
- message="Subject first line\r\nSubject second line\r\n\r\nBody first line\r\nBody second line\r\n" &&
- subject="Subject first line Subject second line" &&
- branch="crlf-two-line-subject" &&
- create_crlf_ref "${message}" "${subject}" "${body}" "${branch}" &&
- message="Subject first line\r\nSubject second line" &&
- subject="Subject first line Subject second line" &&
- body="" &&
- branch="crlf-two-line-subject-no-body" &&
- create_crlf_ref "${message}" "${subject}" "${body}" "${branch}" &&
- message="Subject first line\r\nSubject second line\r\n" &&
- branch="crlf-two-line-subject-no-body-trailing-newline" &&
- create_crlf_ref "${message}" "${subject}" "${body}" "${branch}" &&
- message="Subject first line\r\nSubject second line\r\n\r" &&
- branch="crlf-two-line-subject-no-body-trailing-newline2" &&
- create_crlf_ref "${message}" "${subject}" "${body}" "${branch}"
+ create_crlf_ref crlf <<-\EOF &&
+ Subject first line
+
+ Body first line
+ Body second line
+ EOF
+ create_crlf_ref crlf-empty-lines-after-subject <<-\EOF &&
+ Subject first line
+
+
+ Body first line
+ Body second line
+ EOF
+ create_crlf_ref crlf-two-line-subject <<-\EOF &&
+ Subject first line
+ Subject second line
+
+ Body first line
+ Body second line
+ EOF
+ create_crlf_ref crlf-two-line-subject-no-body <<-\EOF &&
+ Subject first line
+ Subject second line
+ EOF
+ create_crlf_ref crlf-two-line-subject-no-body-trailing-newline <<-\EOF
+ Subject first line
+ Subject second line
+
+ EOF
-test_create_crlf_refs () {
- test_expect_success 'setup refs with CRLF commit messages' '
- create_crlf_refs
- '
-}
-
-cleanup_crlf_refs () {
- for branch in ${LIB_CRLF_BRANCHES}; do
- git branch -D ${branch} &&
- git tag -d tag-${branch} &&
- rm .crlf-message-${branch}.txt &&
- rm .crlf-subject-${branch}.txt &&
- rm .crlf-body-${branch}.txt
- done
-}
-test_cleanup_crlf_refs () {
- test_expect_success 'cleanup refs with CRLF commit messages' '
- cleanup_crlf_refs
- '
}
test_crlf_subject_body_and_contents() {
command_and_args="$@" &&
command=$1 &&
- if [ ${command} = "branch" ] || [ ${command} = "for-each-ref" ] || [ ${command} = "tag" ]; then
+ if test ${command} = "branch" || test ${command} = "for-each-ref" || test ${command} = "tag"
+ then
atoms="(contents:subject) (contents:body) (contents)"
- elif [ ${command} = "log" ] || [ ${command} = "show" ]; then
+ elif test ${command} = "log" || test ${command} = "show"
+ then
atoms="s b B"
fi &&
files="subject body message" &&
- while [ -n "${atoms}" ]; do
+ while test -n "${atoms}"
+ do
set ${atoms} && atom=$1 && shift && atoms="$*" &&
set ${files} && file=$1 && shift && files="$*" &&
- test_expect_success "${command}: --format='%${atom}' works with CRLF input" "
+ test_expect_success "${command}: --format='%${atom}' works with messages using CRLF" "
rm -f expect &&
- for ref in ${LIB_CRLF_BRANCHES}; do
+ for ref in ${LIB_CRLF_BRANCHES}
+ do
cat .crlf-${file}-\"\${ref}\".txt >>expect &&
printf \"\n\" >>expect
done &&
git $command_and_args --format=\"%${atom}\" >actual &&
test_cmp expect actual
"
done
}
+
+
+test_expect_success 'Setup refs with commit and tag messages using CRLF' '
+ test_commit inital &&
+ create_crlf_refs
+'
+
git diff pr-576/phil-blain/fix-branch-verbose-crlf-v3:t/t3203-branch-output.sh HEAD:t/t3920-crlf-messages.sh
@@ -1,111 +1,97 @@
#!/bin/sh
-test_expect_success 'git branch -v works with CRLF input' '
- cat >expect <<-EOF &&
- two
- one
- Subject first line
- Subject first line
- Subject first line Subject second line
- Subject first line Subject second line
- Subject first line Subject second line
- Subject first line Subject second line
- EOF
+test_expect_success 'branch: --verbose works with messages using CRLF' '
+ rm -f expect &&
+ for branch in $LIB_CRLF_BRANCHES
+ do
+ printf " " >>expect &&
+ cat .crlf-subject-${branch}.txt >>expect &&
+ printf "\n" >>expect
+ done &&
git branch -v >tmp &&
# Remove first two columns, and the line for the currently checked out branch
current=$(git branch --show-current) &&
$ git diff pr-576/phil-blain/fix-branch-verbose-crlf-v3:t/t4202-log.sh HEAD:t/t3920-crlf-messages.sh
@@ -1,1930 +1,126 @@
-test_expect_success 'oneline with CRLF messages' '
- for branch in $LIB_CLRF_BRANCHES; do
+test_expect_success 'log: --oneline works with messages using CRLF' '
+ for branch in $LIB_CRLF_BRANCHES
+ do
cat .crlf-subject-${branch}.txt >expect &&
+ printf "\n" >>expect &&
git log --oneline -1 ${branch} >tmp-branch &&
git log --oneline -1 tag-${branch} >tmp-tag &&
- awk "{print \$NF}" <tmp-branch >actual-branch &&
- awk "{print \$NF}" <tmp-tag >actual-tag &&
+ cut -d" " -f2- <tmp-branch >actual-branch &&
+ cut -d" " -f2- <tmp-tag >actual-tag &&
test_cmp expect actual-branch &&
test_cmp expect actual-tag
done