summaryrefslogtreecommitdiff
path: root/tests/resources/generate_crlf.sh
diff options
context:
space:
mode:
Diffstat (limited to 'tests/resources/generate_crlf.sh')
-rwxr-xr-xtests/resources/generate_crlf.sh72
1 files changed, 67 insertions, 5 deletions
diff --git a/tests/resources/generate_crlf.sh b/tests/resources/generate_crlf.sh
index 70534543f..068cad053 100755
--- a/tests/resources/generate_crlf.sh
+++ b/tests/resources/generate_crlf.sh
@@ -8,9 +8,9 @@
# the configuration that git produces.
#
# To update the test resource data, from the test resource directory:
-# git rm -r ./crlf_data
+# git rm -r ./crlf_data/{posix,windows}
# sh ./generate_crlf.sh ./crlf ./crlf_data /tmp/crlf_gitdirs
-# git add ./crlf_data
+# git add ./crlf_data/{posix,windows}
set -e
@@ -25,7 +25,7 @@ tempdir=$3
set -u
-create_repo() {
+create_to_workdir_data() {
local input=$1
local output=$2
local tempdir=$3
@@ -33,7 +33,7 @@ create_repo() {
local autocrlf=$5
local attr=$6
- local worktree="${output}/${systype}/autocrlf_${autocrlf}"
+ local worktree="${output}/${systype}_to_workdir/autocrlf_${autocrlf}"
if [ "$attr" != "" ]; then
local attrdir=`echo $attr | sed -e "s/ /,/g" | sed -e "s/=/_/g"`
@@ -67,6 +67,63 @@ create_repo() {
fi
}
+create_to_odb_data() {
+ local input=$1
+ local output=$2
+ local tempdir=$3
+ local systype=$4
+ local autocrlf=$5
+ local safecrlf=$6
+ local attr=$7
+
+ local destdir="${output}/${systype}_to_odb/autocrlf_${autocrlf},safecrlf_${safecrlf}"
+
+ if [ "$attr" != "" ]; then
+ local attrdir=`echo $attr | sed -e "s/ /,/g" | sed -e "s/=/_/g"`
+ destdir="${destdir},${attrdir}"
+ fi
+
+ if [ "$tempdir" = "" ]; then
+ local workdir="${destdir}/_workdir"
+ else
+ local workdir="${tempdir}/generate_crlf_${RANDOM}"
+ fi
+
+ echo "Creating ${destdir}"
+ mkdir -p "${destdir}"
+
+ git init "${workdir}" >/dev/null
+ git --work-tree="${workdir}" --git-dir="${workdir}/.git" config core.autocrlf "${autocrlf}"
+ git --work-tree="${workdir}" --git-dir="${workdir}/.git" config core.safecrlf "${safecrlf}"
+
+ if [ "$attr" != "" ]; then
+ echo "* ${attr}" > "${workdir}/.gitattributes"
+ fi
+
+ cp ${input}/* ${workdir}
+
+ for path in ${workdir}/*; do
+ filename=$(basename $path)
+ failed=""
+ output=$(git --work-tree="${workdir}" --git-dir="${workdir}/.git" add ${filename} 2>&1) || failed=1
+
+ if [ ! -z "${failed}" -a "${output:0:35}" == "fatal: LF would be replaced by CRLF" ]; then
+ echo "LF would be replaced by CRLF in '${filename}'" > "${destdir}/${filename}.fail"
+ elif [ ! -z "${failed}" -a "${output:0:35}" == "fatal: CRLF would be replaced by LF" ]; then
+ echo "CRLF would be replaced by LF in '${filename}'" > "${destdir}/${filename}.fail"
+ elif [ ! -z "${failed}" ]; then
+ echo "failed to add ${filename}: ${output}" 1>&2
+ exit 1
+ else
+ git --work-tree="${workdir}" --git-dir="${workdir}/.git" cat-file blob ":${filename}" > "${destdir}/${filename}"
+ fi
+ done
+
+ if [ "$tempdir" != "" ]; then
+ rm -rf "${workdir}"
+ fi
+}
+
if [[ `uname -s` == MINGW* ]]; then
systype="windows"
else
@@ -78,8 +135,13 @@ for autocrlf in true false input; do
"text eol=lf" "text eol=crlf" \
"text=auto eol=lf" "text=auto eol=crlf"; do
- create_repo "${input}" "${output}" "${tempdir}" \
+ create_to_workdir_data "${input}" "${output}" "${tempdir}" \
"${systype}" "${autocrlf}" "${attr}"
+
+ for safecrlf in true false warn; do
+ create_to_odb_data "${input}" "${output}" "${tempdir}" \
+ "${systype}" "${autocrlf}" "${safecrlf}" "${attr}"
+ done
done
done