]> git.proxmox.com Git - libgit2.git/blob - tests/generate_crlf.sh
d3fd1bb9a56e011c456439d5c355f11b8b18b298
[libgit2.git] / tests / generate_crlf.sh
1 #!/usr/bin/env bash
2
3 set -e
4
5 if [ "$1" == "" -o "$2" == "" ]; then
6 echo "usage: $0 crlfrepo directory [tempdir]"
7 exit 1
8 fi
9
10 input=$1
11 output=$2
12 tempdir=$3
13
14 set -u
15
16 create_repo() {
17 local input=$1
18 local output=$2
19 local tempdir=$3
20 local systype=$4
21 local autocrlf=$5
22 local attr=$6
23
24 local worktree="${output}/${systype}/autocrlf_${autocrlf}"
25
26 if [ "$attr" != "" ]; then
27 local attrdir=`echo $attr | sed -e "s/ /,/g" | sed -e "s/=/_/g"`
28 worktree="${worktree},${attrdir}"
29 fi
30
31 if [ "$tempdir" = "" ]; then
32 local gitdir="${worktree}/.git"
33 else
34 local gitdir="${tempdir}/generate_crlf_${RANDOM}"
35 fi
36
37 echo "Creating ${worktree}"
38 mkdir -p "${worktree}"
39
40 git clone --no-checkout --quiet --bare "${input}/.gitted" "${gitdir}"
41 git --work-tree="${worktree}" --git-dir="${gitdir}" config core.autocrlf ${autocrlf}
42
43 if [ "$attr" != "" ]; then
44 echo "* ${attr}" >> "${worktree}/.gitattributes"
45 fi
46
47 git --work-tree="${worktree}" --git-dir="${gitdir}" checkout HEAD
48
49 if [ "$attr" != "" ]; then
50 rm "${worktree}/.gitattributes"
51 fi
52
53 if [ "$tempdir" != "" ]; then
54 rm -rf "${gitdir}"
55 fi
56 }
57
58 if [[ `uname -s` == MINGW* ]]; then
59 systype="windows"
60 else
61 systype="posix"
62 fi
63
64 for autocrlf in true false input; do
65 for attr in "" text text=auto -text crlf -crlf eol=lf eol=crlf \
66 "text eol=lf" "text eol=crlf" \
67 "text=auto eol=lf" "text=auto eol=crlf"; do
68
69 create_repo "${input}" "${output}" "${tempdir}" \
70 "${systype}" "${autocrlf}" "${attr}"
71 done
72 done
73