]> git.ipfire.org Git - thirdparty/git.git/blame - t/t9200-git-cvsexportcommit.sh
cvsexportcommit: chomp only removes trailing whitespace
[thirdparty/git.git] / t / t9200-git-cvsexportcommit.sh
CommitLineData
5ab9cc86 1#!/bin/sh
fe142b3a
RR
2#
3# Copyright (c) Robin Rosenberg
4#
ab5a4231 5test_description='Test export of commits to CVS'
fe142b3a
RR
6
7. ./test-lib.sh
8
9cvs >/dev/null 2>&1
10if test $? -ne 1
11then
12 test_expect_success 'skipping git-cvsexportcommit tests, cvs not found' :
13 test_done
14 exit
15fi
16
e32139aa
EW
17CVSROOT=$(pwd)/cvsroot
18CVSWORK=$(pwd)/cvswork
19GIT_DIR=$(pwd)/.git
20export CVSROOT CVSWORK GIT_DIR
21
fe142b3a
RR
22rm -rf "$CVSROOT" "$CVSWORK"
23mkdir "$CVSROOT" &&
24cvs init &&
25cvs -Q co -d "$CVSWORK" . &&
fe142b3a
RR
26echo >empty &&
27git add empty &&
e32139aa 28git commit -q -a -m "Initial" 2>/dev/null ||
fe142b3a
RR
29exit 1
30
c4eaed49
JH
31check_entries () {
32 # $1 == directory, $2 == expected
33 grep '^/' "$1/CVS/Entries" | sort | cut -d/ -f2,3,5 >actual
34 if test -z "$2"
35 then
36 >expected
37 else
38 printf '%s\n' "$2" | tr '|' '\012' >expected
39 fi
82ebb0b6 40 test_cmp expected actual
c4eaed49
JH
41}
42
fe142b3a
RR
43test_expect_success \
44 'New file' \
45 'mkdir A B C D E F &&
46 echo hello1 >A/newfile1.txt &&
47 echo hello2 >B/newfile2.txt &&
48 cp ../test9200a.png C/newfile3.png &&
49 cp ../test9200a.png D/newfile4.png &&
50 git add A/newfile1.txt &&
51 git add B/newfile2.txt &&
52 git add C/newfile3.png &&
53 git add D/newfile4.png &&
54 git commit -a -m "Test: New file" &&
55 id=$(git rev-list --max-count=1 HEAD) &&
56 (cd "$CVSWORK" &&
57 git cvsexportcommit -c $id &&
c4eaed49
JH
58 check_entries A "newfile1.txt/1.1/" &&
59 check_entries B "newfile2.txt/1.1/" &&
60 check_entries C "newfile3.png/1.1/-kb" &&
61 check_entries D "newfile4.png/1.1/-kb" &&
fe142b3a
RR
62 diff A/newfile1.txt ../A/newfile1.txt &&
63 diff B/newfile2.txt ../B/newfile2.txt &&
64 diff C/newfile3.png ../C/newfile3.png &&
65 diff D/newfile4.png ../D/newfile4.png
66 )'
67
68test_expect_success \
69 'Remove two files, add two and update two' \
70 'echo Hello1 >>A/newfile1.txt &&
71 rm -f B/newfile2.txt &&
72 rm -f C/newfile3.png &&
73 echo Hello5 >E/newfile5.txt &&
74 cp ../test9200b.png D/newfile4.png &&
75 cp ../test9200a.png F/newfile6.png &&
76 git add E/newfile5.txt &&
77 git add F/newfile6.png &&
78 git commit -a -m "Test: Remove, add and update" &&
79 id=$(git rev-list --max-count=1 HEAD) &&
80 (cd "$CVSWORK" &&
81 git cvsexportcommit -c $id &&
c4eaed49
JH
82 check_entries A "newfile1.txt/1.2/" &&
83 check_entries B "" &&
84 check_entries C "" &&
85 check_entries D "newfile4.png/1.2/-kb" &&
86 check_entries E "newfile5.txt/1.1/" &&
87 check_entries F "newfile6.png/1.1/-kb" &&
fe142b3a
RR
88 diff A/newfile1.txt ../A/newfile1.txt &&
89 diff D/newfile4.png ../D/newfile4.png &&
90 diff E/newfile5.txt ../E/newfile5.txt &&
91 diff F/newfile6.png ../F/newfile6.png
92 )'
93
94# Should fail (but only on the git-cvsexportcommit stage)
95test_expect_success \
96 'Fail to change binary more than one generation old' \
97 'cat F/newfile6.png >>D/newfile4.png &&
98 git commit -a -m "generatiion 1" &&
99 cat F/newfile6.png >>D/newfile4.png &&
100 git commit -a -m "generation 2" &&
101 id=$(git rev-list --max-count=1 HEAD) &&
102 (cd "$CVSWORK" &&
103 ! git cvsexportcommit -c $id
104 )'
105
e86ad71f
RR
106#test_expect_success \
107# 'Fail to remove binary file more than one generation old' \
108# 'git reset --hard HEAD^ &&
109# cat F/newfile6.png >>D/newfile4.png &&
110# git commit -a -m "generation 2 (again)" &&
111# rm -f D/newfile4.png &&
112# git commit -a -m "generation 3" &&
113# id=$(git rev-list --max-count=1 HEAD) &&
114# (cd "$CVSWORK" &&
115# ! git cvsexportcommit -c $id
116# )'
fe142b3a
RR
117
118# We reuse the state from two tests back here
119
120# This test is here because a patch for only binary files will
121# fail with gnu patch, so cvsexportcommit must handle that.
122test_expect_success \
123 'Remove only binary files' \
e86ad71f 124 'git reset --hard HEAD^^ &&
fe142b3a
RR
125 rm -f D/newfile4.png &&
126 git commit -a -m "test: remove only a binary file" &&
127 id=$(git rev-list --max-count=1 HEAD) &&
128 (cd "$CVSWORK" &&
129 git cvsexportcommit -c $id &&
c4eaed49
JH
130 check_entries A "newfile1.txt/1.2/" &&
131 check_entries B "" &&
132 check_entries C "" &&
133 check_entries D "" &&
134 check_entries E "newfile5.txt/1.1/" &&
135 check_entries F "newfile6.png/1.1/-kb" &&
fe142b3a
RR
136 diff A/newfile1.txt ../A/newfile1.txt &&
137 diff E/newfile5.txt ../E/newfile5.txt &&
138 diff F/newfile6.png ../F/newfile6.png
139 )'
140
141test_expect_success \
142 'Remove only a text file' \
143 'rm -f A/newfile1.txt &&
144 git commit -a -m "test: remove only a binary file" &&
145 id=$(git rev-list --max-count=1 HEAD) &&
146 (cd "$CVSWORK" &&
147 git cvsexportcommit -c $id &&
c4eaed49
JH
148 check_entries A "" &&
149 check_entries B "" &&
150 check_entries C "" &&
151 check_entries D "" &&
152 check_entries E "newfile5.txt/1.1/" &&
153 check_entries F "newfile6.png/1.1/-kb" &&
fe142b3a
RR
154 diff E/newfile5.txt ../E/newfile5.txt &&
155 diff F/newfile6.png ../F/newfile6.png
156 )'
157
e86ad71f
RR
158test_expect_success \
159 'New file with spaces in file name' \
160 'mkdir "G g" &&
161 echo ok then >"G g/with spaces.txt" &&
162 git add "G g/with spaces.txt" && \
163 cp ../test9200a.png "G g/with spaces.png" && \
164 git add "G g/with spaces.png" &&
165 git commit -a -m "With spaces" &&
166 id=$(git rev-list --max-count=1 HEAD) &&
167 (cd "$CVSWORK" &&
168 git-cvsexportcommit -c $id &&
c4eaed49 169 check_entries "G g" "with spaces.png/1.1/-kb|with spaces.txt/1.1/"
e86ad71f
RR
170 )'
171
172test_expect_success \
173 'Update file with spaces in file name' \
174 'echo Ok then >>"G g/with spaces.txt" &&
175 cat ../test9200a.png >>"G g/with spaces.png" && \
176 git add "G g/with spaces.png" &&
177 git commit -a -m "Update with spaces" &&
178 id=$(git rev-list --max-count=1 HEAD) &&
179 (cd "$CVSWORK" &&
180 git-cvsexportcommit -c $id
c4eaed49 181 check_entries "G g" "with spaces.png/1.2/-kb|with spaces.txt/1.2/"
e86ad71f
RR
182 )'
183
133f0810
JH
184# Some filesystems mangle pathnames with UTF-8 characters --
185# check and skip
186if p="Å/goo/a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/z/å/ä/ö" &&
187 mkdir -p "tst/$p" &&
188 date >"tst/$p/day" &&
189 found=$(find tst -type f -print) &&
190 test "z$found" = "ztst/$p/day" &&
191 rm -fr tst
192then
193
1a91ebf9 194# This test contains UTF-8 characters
e86ad71f
RR
195test_expect_success \
196 'File with non-ascii file name' \
1a91ebf9
JH
197 'mkdir -p Å/goo/a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/z/å/ä/ö &&
198 echo Foo >Å/goo/a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/z/å/ä/ö/gårdetsågårdet.txt &&
199 git add Å/goo/a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/z/å/ä/ö/gårdetsågårdet.txt &&
200 cp ../test9200a.png Å/goo/a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/z/å/ä/ö/gårdetsågårdet.png &&
201 git add Å/goo/a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/z/å/ä/ö/gårdetsågårdet.png &&
202 git commit -a -m "Går det så går det" && \
e86ad71f
RR
203 id=$(git rev-list --max-count=1 HEAD) &&
204 (cd "$CVSWORK" &&
205 git-cvsexportcommit -v -c $id &&
c4eaed49
JH
206 check_entries \
207 "Å/goo/a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/z/å/ä/ö" \
208 "gårdetsågårdet.png/1.1/-kb|gårdetsågårdet.txt/1.1/"
e86ad71f
RR
209 )'
210
133f0810
JH
211fi
212
213rm -fr tst
214
e86ad71f
RR
215test_expect_success \
216 'Mismatching patch should fail' \
217 'date >>"E/newfile5.txt" &&
218 git add "E/newfile5.txt" &&
219 git commit -a -m "Update one" &&
220 date >>"E/newfile5.txt" &&
221 git add "E/newfile5.txt" &&
222 git commit -a -m "Update two" &&
223 id=$(git rev-list --max-count=1 HEAD) &&
224 (cd "$CVSWORK" &&
225 ! git-cvsexportcommit -c $id
226 )'
227
5c66d0d4 228case "$(git config --bool core.filemode)" in
3c23d66f
JH
229false)
230 ;;
231*)
e86ad71f
RR
232test_expect_success \
233 'Retain execute bit' \
234 'mkdir G &&
235 echo executeon >G/on &&
236 chmod +x G/on &&
237 echo executeoff >G/off &&
238 git add G/on &&
239 git add G/off &&
240 git commit -a -m "Execute test" &&
241 (cd "$CVSWORK" &&
242 git-cvsexportcommit -c HEAD
243 test -x G/on &&
244 ! test -x G/off
245 )'
3c23d66f
JH
246 ;;
247esac
7c0f7028 248
a7237594 249test_expect_success '-w option should work with relative GIT_DIR' '
ab5a4231
JH
250 mkdir W &&
251 echo foobar >W/file1.txt &&
252 echo bazzle >W/file2.txt &&
253 git add W/file1.txt &&
254 git add W/file2.txt &&
255 git commit -m "More updates" &&
256 id=$(git rev-list --max-count=1 HEAD) &&
257 (cd "$GIT_DIR" &&
258 GIT_DIR=. git cvsexportcommit -w "$CVSWORK" -c $id &&
259 check_entries "$CVSWORK/W" "file1.txt/1.1/|file2.txt/1.1/" &&
82ebb0b6
JK
260 test_cmp "$CVSWORK/W/file1.txt" ../W/file1.txt &&
261 test_cmp "$CVSWORK/W/file2.txt" ../W/file2.txt
ab5a4231
JH
262 )
263'
264
fef3a7cc
JS
265test_expect_success 'check files before directories' '
266
267 echo Notes > release-notes &&
268 git add release-notes &&
269 git commit -m "Add release notes" release-notes &&
270 id=$(git rev-parse HEAD) &&
271 git cvsexportcommit -w "$CVSWORK" -c $id &&
272
273 echo new > DS &&
274 echo new > E/DS &&
275 echo modified > release-notes &&
276 git add DS E/DS release-notes &&
277 git commit -m "Add two files with the same basename" &&
278 id=$(git rev-parse HEAD) &&
279 git cvsexportcommit -w "$CVSWORK" -c $id &&
280 check_entries "$CVSWORK/E" "DS/1.1/|newfile5.txt/1.1/" &&
281 check_entries "$CVSWORK" "DS/1.1/|release-notes/1.2/" &&
82ebb0b6
JK
282 test_cmp "$CVSWORK/DS" DS &&
283 test_cmp "$CVSWORK/E/DS" E/DS &&
284 test_cmp "$CVSWORK/release-notes" release-notes
fef3a7cc
JS
285
286'
287
288test_expect_success 'commit a file with leading spaces in the name' '
289
290 echo space > " space" &&
291 git add " space" &&
292 git commit -m "Add a file with a leading space" &&
293 id=$(git rev-parse HEAD) &&
294 git cvsexportcommit -w "$CVSWORK" -c $id &&
295 check_entries "$CVSWORK" " space/1.1/|DS/1.1/|release-notes/1.2/" &&
82ebb0b6 296 test_cmp "$CVSWORK/ space" " space"
fef3a7cc
JS
297
298'
299
fe142b3a 300test_done