b7a779b788c281611c50ab17d6dcb9e7136dc4e9
1 #!/bin/sh
2 #
3 # Copyright (c) 2008 Matthew Ogilvie
4 # Parts adapted from other tests.
5 #
7 test_description='git-cvsserver -kb modes
9 tests -kb mode for binary files when accessing a git
10 repository using cvs CLI client via git-cvsserver server'
12 . ./test-lib.sh
14 q_to_nul () {
15 perl -pe 'y/Q/\000/'
16 }
18 q_to_cr () {
19 tr Q '\015'
20 }
22 marked_as () {
23 foundEntry="$(grep "^/$2/" "$1/CVS/Entries")"
24 if [ x"$foundEntry" = x"" ] ; then
25 echo "NOT FOUND: $1 $2 1 $3" >> "${WORKDIR}/marked.log"
26 return 1
27 fi
28 test x"$(grep "^/$2/" "$1/CVS/Entries" | cut -d/ -f5)" = x"$3"
29 stat=$?
30 echo "$1 $2 $stat '$3'" >> "${WORKDIR}/marked.log"
31 return $stat
32 }
34 not_present() {
35 foundEntry="$(grep "^/$2/" "$1/CVS/Entries")"
36 if [ -r "$1/$2" ] ; then
37 echo "Error: File still exists: $1 $2" >> "${WORKDIR}/marked.log"
38 return 1;
39 fi
40 if [ x"$foundEntry" != x"" ] ; then
41 echo "Error: should not have found: $1 $2" >> "${WORKDIR}/marked.log"
42 return 1;
43 else
44 echo "Correctly not found: $1 $2" >> "${WORKDIR}/marked.log"
45 return 0;
46 fi
47 }
49 cvs >/dev/null 2>&1
50 if test $? -ne 1
51 then
52 test_expect_success 'skipping git-cvsserver tests, cvs not found' :
53 test_done
54 exit
55 fi
56 perl -e 'use DBI; use DBD::SQLite' >/dev/null 2>&1 || {
57 test_expect_success 'skipping git-cvsserver tests, Perl SQLite interface unavailable' :
58 test_done
59 exit
60 }
62 unset GIT_DIR GIT_CONFIG
63 WORKDIR=$(pwd)
64 SERVERDIR=$(pwd)/gitcvs.git
65 git_config="$SERVERDIR/config"
66 CVSROOT=":fork:$SERVERDIR"
67 CVSWORK="$(pwd)/cvswork"
68 CVS_SERVER=git-cvsserver
69 export CVSROOT CVS_SERVER
71 rm -rf "$CVSWORK" "$SERVERDIR"
72 test_expect_success 'setup' '
73 echo "Simple text file" >textfile.c &&
74 echo "File with embedded NUL: Q <- there" | q_to_nul > binfile.bin &&
75 mkdir subdir &&
76 echo "Another text file" > subdir/file.h &&
77 echo "Another binary: Q (this time CR)" | q_to_cr > subdir/withCr.bin &&
78 echo "Mixed up NUL, but marked text: Q <- there" | q_to_nul > mixedUp.c
79 echo "Unspecified" > subdir/unspecified.other &&
80 echo "/*.bin -crlf" > .gitattributes &&
81 echo "/*.c crlf" >> .gitattributes &&
82 echo "subdir/*.bin -crlf" >> .gitattributes &&
83 echo "subdir/*.c crlf" >> .gitattributes &&
84 echo "subdir/file.h crlf" >> .gitattributes &&
85 git add .gitattributes textfile.c binfile.bin mixedUp.c subdir/* &&
86 git commit -q -m "First Commit" &&
87 git clone -q --local --bare "$WORKDIR/.git" "$SERVERDIR" >/dev/null 2>&1 &&
88 GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled true &&
89 GIT_DIR="$SERVERDIR" git config gitcvs.logfile "$SERVERDIR/gitcvs.log"
90 '
92 test_expect_success 'cvs co (default crlf)' '
93 GIT_CONFIG="$git_config" cvs -Q co -d cvswork master >cvs.log 2>&1 &&
94 test x"$(grep '/-k' cvswork/CVS/Entries cvswork/subdir/CVS/Entries)" = x""
95 '
97 rm -rf cvswork
98 test_expect_success 'cvs co (allbinary)' '
99 GIT_DIR="$SERVERDIR" git config --bool gitcvs.allbinary true &&
100 GIT_CONFIG="$git_config" cvs -Q co -d cvswork master >cvs.log 2>&1 &&
101 marked_as cvswork textfile.c -kb &&
102 marked_as cvswork binfile.bin -kb &&
103 marked_as cvswork .gitattributes -kb &&
104 marked_as cvswork mixedUp.c -kb &&
105 marked_as cvswork/subdir withCr.bin -kb &&
106 marked_as cvswork/subdir file.h -kb &&
107 marked_as cvswork/subdir unspecified.other -kb
108 '
110 rm -rf cvswork cvs.log
111 test_expect_success 'cvs co (use attributes/allbinary)' '
112 GIT_DIR="$SERVERDIR" git config --bool gitcvs.usecrlfattr true &&
113 GIT_CONFIG="$git_config" cvs -Q co -d cvswork master >cvs.log 2>&1 &&
114 marked_as cvswork textfile.c "" &&
115 marked_as cvswork binfile.bin -kb &&
116 marked_as cvswork .gitattributes -kb &&
117 marked_as cvswork mixedUp.c "" &&
118 marked_as cvswork/subdir withCr.bin -kb &&
119 marked_as cvswork/subdir file.h "" &&
120 marked_as cvswork/subdir unspecified.other -kb
121 '
123 rm -rf cvswork
124 test_expect_success 'cvs co (use attributes)' '
125 GIT_DIR="$SERVERDIR" git config --bool gitcvs.allbinary false &&
126 GIT_CONFIG="$git_config" cvs -Q co -d cvswork master >cvs.log 2>&1 &&
127 marked_as cvswork textfile.c "" &&
128 marked_as cvswork binfile.bin -kb &&
129 marked_as cvswork .gitattributes "" &&
130 marked_as cvswork mixedUp.c "" &&
131 marked_as cvswork/subdir withCr.bin -kb &&
132 marked_as cvswork/subdir file.h "" &&
133 marked_as cvswork/subdir unspecified.other ""
134 '
136 test_expect_success 'adding files' '
137 cd cvswork/subdir &&
138 echo "more text" > src.c &&
139 GIT_CONFIG="$git_config" cvs -Q add src.c >cvs.log 2>&1 &&
140 marked_as . src.c "" &&
141 echo "psuedo-binary" > temp.bin &&
142 cd .. &&
143 GIT_CONFIG="$git_config" cvs -Q add subdir/temp.bin >cvs.log 2>&1 &&
144 marked_as subdir temp.bin "-kb" &&
145 cd subdir &&
146 GIT_CONFIG="$git_config" cvs -Q ci -m "adding files" >cvs.log 2>&1 &&
147 marked_as . temp.bin "-kb" &&
148 marked_as . src.c ""
149 '
151 cd "$WORKDIR"
152 test_expect_success 'updating' '
153 git pull gitcvs.git &&
154 echo 'hi' > subdir/newfile.bin &&
155 echo 'junk' > subdir/file.h &&
156 echo 'hi' > subdir/newfile.c &&
157 echo 'hello' >> binfile.bin &&
158 git add subdir/newfile.bin subdir/file.h subdir/newfile.c binfile.bin &&
159 git commit -q -m "Add and change some files" &&
160 git push gitcvs.git >/dev/null &&
161 cd cvswork &&
162 GIT_CONFIG="$git_config" cvs -Q update &&
163 cd .. &&
164 marked_as cvswork textfile.c "" &&
165 marked_as cvswork binfile.bin -kb &&
166 marked_as cvswork .gitattributes "" &&
167 marked_as cvswork mixedUp.c "" &&
168 marked_as cvswork/subdir withCr.bin -kb &&
169 marked_as cvswork/subdir file.h "" &&
170 marked_as cvswork/subdir unspecified.other "" &&
171 marked_as cvswork/subdir newfile.bin -kb &&
172 marked_as cvswork/subdir newfile.c "" &&
173 echo "File with embedded NUL: Q <- there" | q_to_nul > tmpExpect1 &&
174 echo "hello" >> tmpExpect1 &&
175 cmp cvswork/binfile.bin tmpExpect1
176 '
178 test_done