]>
git.proxmox.com Git - libgit2.git/blob - tests/resources/generate_crlf.sh
3 # This script will generate the test corpus for CR/LF data using git;
4 # we create files with all possible line ending varieties (all LF, all
5 # CRLF, mixed, etc) on all the possible line ending configurations
6 # (`core.autocrlf=true`, `text=auto` in gitattributes, etc). This
7 # allows us to validate that our configuration will match byte-for-byte
8 # the configuration that git produces.
10 # To update the test resource data, from the test resource directory:
11 # git rm -r ./crlf_data/{posix,windows}
12 # sh ./generate_crlf.sh ./crlf ./crlf_data /tmp/crlf_gitdirs
13 # git add ./crlf_data/{posix,windows}
17 if [ "$1" == "" -o "$2" == "" ]; then
18 echo "usage: $0 crlfrepo directory [tempdir]"
28 create_to_workdir_data
() {
36 local worktree
="${output}/${systype}_to_workdir/autocrlf_${autocrlf}"
38 if [ "$attr" != "" ]; then
39 local attrdir
=`echo $attr | sed -e "s/ /,/g" | sed -e "s/=/_/g"`
40 worktree
="${worktree},${attrdir}"
43 if [ "$tempdir" = "" ]; then
44 local gitdir
="${worktree}/.git"
46 local gitdir
="${tempdir}/generate_crlf_${RANDOM}"
49 echo "Creating ${worktree}"
50 mkdir
-p "${worktree}"
52 git clone
--no-checkout --quiet --bare "${input}/.gitted" "${gitdir}"
53 git
--work-tree="${worktree}" --git-dir="${gitdir}" config core.autocrlf ${autocrlf}
55 if [ "$attr" != "" ]; then
56 echo "* ${attr}" >> "${worktree}/.gitattributes
"
59 git --work-tree="${worktree}" --git-dir="${gitdir}" checkout HEAD
61 if [ "$attr" != "" ]; then
62 rm "${worktree}/.gitattributes
"
65 if [ "$tempdir" != "" ]; then
70 create_to_odb_data() {
79 local destdir="${output}/${systype}_to_odb/autocrlf_${autocrlf},safecrlf_${safecrlf}"
81 if [ "$attr" != "" ]; then
82 local attrdir=`echo $attr | sed -e "s
/ /,/g
" | sed -e "s
/=/_
/g
"`
83 destdir="${destdir},${attrdir}"
86 if [ "$tempdir" = "" ]; then
87 local workdir="${destdir}/_workdir
"
89 local workdir="${tempdir}/generate_crlf_
${RANDOM}"
92 echo "Creating
${destdir}"
95 git init "${workdir}" >/dev/null
96 git --work-tree="${workdir}" --git-dir="${workdir}/.git" config core.autocrlf "${autocrlf}"
97 git --work-tree="${workdir}" --git-dir="${workdir}/.git" config core.safecrlf "${safecrlf}"
99 if [ "$attr" != "" ]; then
100 echo "* ${attr}" > "${workdir}/.gitattributes
"
103 cp ${input}/* ${workdir}
105 for path in ${workdir}/*; do
106 filename=$(basename $path)
108 output=$(git --work-tree="${workdir}" --git-dir="${workdir}/.git" add ${filename} 2>&1) || failed
=1
110 if [ ! -z "${failed}" -a "${output:0:35}" == "fatal: LF would be replaced by CRLF" ]; then
111 echo "LF would be replaced by CRLF in '${filename}'" > "${destdir}/${filename}.fail"
112 elif [ ! -z "${failed}" -a "${output:0:35}" == "fatal: CRLF would be replaced by LF" ]; then
113 echo "CRLF would be replaced by LF in '${filename}'" > "${destdir}/${filename}.fail"
114 elif [ ! -z "${failed}" ]; then
115 echo "failed to add ${filename}: ${output}" 1>&2
118 git
--work-tree="${workdir}" --git-dir="${workdir}/.git" cat-file blob ":${filename}" > "${destdir}/${filename}"
122 if [ "$tempdir" != "" ]; then
127 if [[ `uname -s` == MINGW
* ]]; then
133 for autocrlf
in true false input
; do
134 for attr
in "" text text
=auto
-text crlf
-crlf eol
=lf eol
=crlf \
135 "text eol=lf" "text eol=crlf" \
136 "text=auto eol=lf" "text=auto eol=crlf"; do
138 create_to_workdir_data
"${input}" "${output}" "${tempdir}" \
139 "${systype}" "${autocrlf}" "${attr}"
141 for safecrlf
in true false warn
; do
142 create_to_odb_data
"${input}" "${output}" "${tempdir}" \
143 "${systype}" "${autocrlf}" "${safecrlf}" "${attr}"