blob: 8b5681dd68ab05adc504437a54ff2877ed180516 [file] [log] [blame]
Eric Wong36f5b1f2006-05-23 19:23:41 -07001#!/bin/sh
2#
3# Copyright (c) 2006 Eric Wong
4#
5
Nanako Shiraishi1364ff22008-09-08 19:02:08 +09006test_description='git svn property tests'
Eric Wong36f5b1f2006-05-23 19:23:41 -07007. ./lib-git-svn.sh
8
9mkdir import
10
11a_crlf=
12a_lf=
13a_cr=
14a_ne_crlf=
15a_ne_lf=
16a_ne_cr=
17a_empty=
18a_empty_lf=
19a_empty_cr=
20a_empty_crlf=
21
22cd import
Eric Wong3c4c7352006-05-29 19:03:45 -070023 cat >> kw.c <<\EOF
Eric Wongdc62e252006-06-28 03:07:14 -070024/* Somebody prematurely put a keyword into this file */
25/* $Id$ */
Eric Wong3c4c7352006-05-29 19:03:45 -070026EOF
Eric Wong36f5b1f2006-05-23 19:23:41 -070027
28 printf "Hello\r\nWorld\r\n" > crlf
Elia Pintoe10de5a2016-01-12 10:45:10 +000029 a_crlf=$(git hash-object -w crlf)
Eric Wong36f5b1f2006-05-23 19:23:41 -070030 printf "Hello\rWorld\r" > cr
Elia Pintoe10de5a2016-01-12 10:45:10 +000031 a_cr=$(git hash-object -w cr)
Eric Wong36f5b1f2006-05-23 19:23:41 -070032 printf "Hello\nWorld\n" > lf
Elia Pintoe10de5a2016-01-12 10:45:10 +000033 a_lf=$(git hash-object -w lf)
Eric Wong36f5b1f2006-05-23 19:23:41 -070034
35 printf "Hello\r\nWorld" > ne_crlf
Elia Pintoe10de5a2016-01-12 10:45:10 +000036 a_ne_crlf=$(git hash-object -w ne_crlf)
Eric Wong36f5b1f2006-05-23 19:23:41 -070037 printf "Hello\nWorld" > ne_lf
Elia Pintoe10de5a2016-01-12 10:45:10 +000038 a_ne_lf=$(git hash-object -w ne_lf)
Eric Wong36f5b1f2006-05-23 19:23:41 -070039 printf "Hello\rWorld" > ne_cr
Elia Pintoe10de5a2016-01-12 10:45:10 +000040 a_ne_cr=$(git hash-object -w ne_cr)
Eric Wong36f5b1f2006-05-23 19:23:41 -070041
42 touch empty
Elia Pintoe10de5a2016-01-12 10:45:10 +000043 a_empty=$(git hash-object -w empty)
Eric Wong36f5b1f2006-05-23 19:23:41 -070044 printf "\n" > empty_lf
Elia Pintoe10de5a2016-01-12 10:45:10 +000045 a_empty_lf=$(git hash-object -w empty_lf)
Eric Wong36f5b1f2006-05-23 19:23:41 -070046 printf "\r" > empty_cr
Elia Pintoe10de5a2016-01-12 10:45:10 +000047 a_empty_cr=$(git hash-object -w empty_cr)
Eric Wong36f5b1f2006-05-23 19:23:41 -070048 printf "\r\n" > empty_crlf
Elia Pintoe10de5a2016-01-12 10:45:10 +000049 a_empty_crlf=$(git hash-object -w empty_crlf)
Eric Wong36f5b1f2006-05-23 19:23:41 -070050
Eygene Ryabinkinda083d62009-05-08 12:06:16 +040051 svn_cmd import --no-auto-props -m 'import for git svn' . "$svnrepo" >/dev/null
Eric Wong36f5b1f2006-05-23 19:23:41 -070052cd ..
53
54rm -rf import
Bryan Donlanf69e8362008-05-04 01:37:59 -040055test_expect_success 'checkout working copy from svn' 'svn co "$svnrepo" test_wc'
Jonathan Nieder18a82692010-09-06 20:42:54 -050056test_expect_success 'setup some commits to svn' '
57 (
58 cd test_wc &&
Eric Wong42d32872006-06-13 04:02:23 -070059 echo Greetings >> kw.c &&
Michael Spang7b3fab82007-02-12 19:33:37 -050060 poke kw.c &&
Eygene Ryabinkinda083d62009-05-08 12:06:16 +040061 svn_cmd commit -m "Not yet an Id" &&
Eric Wong42d32872006-06-13 04:02:23 -070062 echo Hello world >> kw.c &&
Michael Spang7b3fab82007-02-12 19:33:37 -050063 poke kw.c &&
Eygene Ryabinkinda083d62009-05-08 12:06:16 +040064 svn_cmd commit -m "Modified file, but still not yet an Id" &&
65 svn_cmd propset svn:keywords Id kw.c &&
Michael Spang7b3fab82007-02-12 19:33:37 -050066 poke kw.c &&
Jens Lehmannfd4ec4f2010-09-06 20:39:54 +020067 svn_cmd commit -m "Propset Id"
Jonathan Nieder18a82692010-09-06 20:42:54 -050068 )
69'
Eric Wong36f5b1f2006-05-23 19:23:41 -070070
Nanako Shiraishif9647322008-09-10 06:25:27 +090071test_expect_success 'initialize git svn' 'git svn init "$svnrepo"'
Nanako Shiraishi1364ff22008-09-08 19:02:08 +090072test_expect_success 'fetch revisions from svn' 'git svn fetch'
Eric Wong36f5b1f2006-05-23 19:23:41 -070073
Eric Wong36f5b1f2006-05-23 19:23:41 -070074name='test svn:keywords ignoring'
Eric Wong42d32872006-06-13 04:02:23 -070075test_expect_success "$name" \
Jeff Kinge1c0c152016-05-13 16:47:14 -040076 'git checkout -b mybranch remotes/git-svn &&
Eric Wong42d32872006-06-13 04:02:23 -070077 echo Hi again >> kw.c &&
Pavel Roskin3dff5372007-02-03 23:49:16 -050078 git commit -a -m "test keywords ignoring" &&
Jeff Kinge1c0c152016-05-13 16:47:14 -040079 git svn set-tree remotes/git-svn..mybranch &&
80 git pull . remotes/git-svn'
Eric Wong36f5b1f2006-05-23 19:23:41 -070081
82expect='/* $Id$ */'
Elia Pintoe10de5a2016-01-12 10:45:10 +000083got="$(sed -ne 2p kw.c)"
Eric Wong36f5b1f2006-05-23 19:23:41 -070084test_expect_success 'raw $Id$ found in kw.c' "test '$expect' = '$got'"
85
Jonathan Nieder18a82692010-09-06 20:42:54 -050086test_expect_success "propset CR on crlf files" '
87 (
88 cd test_wc &&
Eygene Ryabinkinda083d62009-05-08 12:06:16 +040089 svn_cmd propset svn:eol-style CR empty &&
90 svn_cmd propset svn:eol-style CR crlf &&
91 svn_cmd propset svn:eol-style CR ne_crlf &&
Jens Lehmannfd4ec4f2010-09-06 20:39:54 +020092 svn_cmd commit -m "propset CR on crlf files"
Jonathan Nieder18a82692010-09-06 20:42:54 -050093 )
94'
Eric Wong36f5b1f2006-05-23 19:23:41 -070095
Eric Wong42d32872006-06-13 04:02:23 -070096test_expect_success 'fetch and pull latest from svn and checkout a new wc' \
Nanako Shiraishi1364ff22008-09-08 19:02:08 +090097 'git svn fetch &&
Jeff Kinge1c0c152016-05-13 16:47:14 -040098 git pull . remotes/git-svn &&
Eygene Ryabinkinda083d62009-05-08 12:06:16 +040099 svn_cmd co "$svnrepo" new_wc'
Eric Wong36f5b1f2006-05-23 19:23:41 -0700100
Eric Wong36f5b1f2006-05-23 19:23:41 -0700101for i in crlf ne_crlf lf ne_lf cr ne_cr empty_cr empty_lf empty empty_crlf
102do
103 test_expect_success "Comparing $i" "cmp $i new_wc/$i"
104done
105
106
107cd test_wc
108 printf '$Id$\rHello\rWorld\r' > cr
109 printf '$Id$\rHello\rWorld' > ne_cr
Elia Pintoe10de5a2016-01-12 10:45:10 +0000110 a_cr=$(printf '$Id$\r\nHello\r\nWorld\r\n' | git hash-object --stdin)
111 a_ne_cr=$(printf '$Id$\r\nHello\r\nWorld' | git hash-object --stdin)
Eric Wong42d32872006-06-13 04:02:23 -0700112 test_expect_success 'Set CRLF on cr files' \
Eygene Ryabinkinda083d62009-05-08 12:06:16 +0400113 'svn_cmd propset svn:eol-style CRLF cr &&
114 svn_cmd propset svn:eol-style CRLF ne_cr &&
115 svn_cmd propset svn:keywords Id cr &&
116 svn_cmd propset svn:keywords Id ne_cr &&
117 svn_cmd commit -m "propset CRLF on cr files"'
Eric Wong36f5b1f2006-05-23 19:23:41 -0700118cd ..
Eric Wong42d32872006-06-13 04:02:23 -0700119test_expect_success 'fetch and pull latest from svn' \
Jeff Kinge1c0c152016-05-13 16:47:14 -0400120 'git svn fetch && git pull . remotes/git-svn'
Eric Wong36f5b1f2006-05-23 19:23:41 -0700121
Elia Pintoe10de5a2016-01-12 10:45:10 +0000122b_cr="$(git hash-object cr)"
123b_ne_cr="$(git hash-object ne_cr)"
Eric Wong36f5b1f2006-05-23 19:23:41 -0700124
125test_expect_success 'CRLF + $Id$' "test '$a_cr' = '$b_cr'"
126test_expect_success 'CRLF + $Id$ (no newline)' "test '$a_ne_cr' = '$b_ne_cr'"
127
Eric Wongad2f9082007-01-11 17:55:50 -0800128cat > show-ignore.expect <<\EOF
129
130# /
131/no-such-file*
132
Benoit Sigoured05ddec2007-10-16 16:36:49 +0200133# /deeply/
Eric Wongad2f9082007-01-11 17:55:50 -0800134/deeply/no-such-file*
135
Benoit Sigoured05ddec2007-10-16 16:36:49 +0200136# /deeply/nested/
Eric Wongad2f9082007-01-11 17:55:50 -0800137/deeply/nested/no-such-file*
138
Benoit Sigoured05ddec2007-10-16 16:36:49 +0200139# /deeply/nested/directory/
Eric Wongad2f9082007-01-11 17:55:50 -0800140/deeply/nested/directory/no-such-file*
141EOF
142
143test_expect_success 'test show-ignore' "
Jonathan Nieder18a82692010-09-06 20:42:54 -0500144 (
145 cd test_wc &&
146 mkdir -p deeply/nested/directory &&
147 touch deeply/nested/directory/.keep &&
148 svn_cmd add deeply &&
149 svn_cmd up &&
150 svn_cmd propset -R svn:ignore '
Michael Haggertya7d72542009-08-07 21:21:21 +0200151no-such-file*
Eric Sunshinecff42432018-07-01 20:24:04 -0400152' . &&
Jonathan Nieder18a82692010-09-06 20:42:54 -0500153 svn_cmd commit -m 'propset svn:ignore'
Jens Lehmannfd4ec4f2010-09-06 20:39:54 +0200154 ) &&
Nanako Shiraishi1364ff22008-09-08 19:02:08 +0900155 git svn show-ignore > show-ignore.got &&
Eric Wongad2f9082007-01-11 17:55:50 -0800156 cmp show-ignore.expect show-ignore.got
Jonathan Nieder18a82692010-09-06 20:42:54 -0500157"
Eric Wongad2f9082007-01-11 17:55:50 -0800158
Benoit Sigoured05ddec2007-10-16 16:36:49 +0200159cat >create-ignore.expect <<\EOF
160/no-such-file*
161EOF
162
brian m. carlson3e04b6e2020-06-19 22:39:39 +0000163expectoid=$(git hash-object create-ignore.expect)
164
165cat >create-ignore-index.expect <<EOF
166100644 $expectoid 0 .gitignore
167100644 $expectoid 0 deeply/.gitignore
168100644 $expectoid 0 deeply/nested/.gitignore
169100644 $expectoid 0 deeply/nested/directory/.gitignore
Benoit Sigoured05ddec2007-10-16 16:36:49 +0200170EOF
171
172test_expect_success 'test create-ignore' "
Jeff Kinge1c0c152016-05-13 16:47:14 -0400173 git svn fetch && git pull . remotes/git-svn &&
Nanako Shiraishi1364ff22008-09-08 19:02:08 +0900174 git svn create-ignore &&
Benoit Sigoured05ddec2007-10-16 16:36:49 +0200175 cmp ./.gitignore create-ignore.expect &&
176 cmp ./deeply/.gitignore create-ignore.expect &&
177 cmp ./deeply/nested/.gitignore create-ignore.expect &&
178 cmp ./deeply/nested/directory/.gitignore create-ignore.expect &&
Matthew DeVoreb00b6ac2018-10-05 14:54:06 -0700179 git ls-files -s >ls_files_result &&
180 grep gitignore ls_files_result | cmp - create-ignore-index.expect
Benoit Sigoured05ddec2007-10-16 16:36:49 +0200181 "
182
Benoit Sigoure15153452007-10-16 16:36:50 +0200183cat >prop.expect <<\EOF
Michael Haggertya7d72542009-08-07 21:21:21 +0200184
Benoit Sigoure15153452007-10-16 16:36:50 +0200185no-such-file*
186
187EOF
188cat >prop2.expect <<\EOF
1898
190EOF
191
192# This test can be improved: since all the svn:ignore contain the same
193# pattern, it can pass even though the propget did not execute on the
194# right directory.
Matthew DeVoreb00b6ac2018-10-05 14:54:06 -0700195test_expect_success 'test propget' '
196 test_propget () {
197 git svn propget $1 $2 >actual &&
198 cmp $3 actual
199 } &&
200 test_propget svn:ignore . prop.expect &&
Benoit Sigoure15153452007-10-16 16:36:50 +0200201 cd deeply &&
Matthew DeVoreb00b6ac2018-10-05 14:54:06 -0700202 test_propget svn:ignore . ../prop.expect &&
203 test_propget svn:entry:committed-rev nested/directory/.keep \
204 ../prop2.expect &&
205 test_propget svn:ignore .. ../prop.expect &&
206 test_propget svn:ignore nested/ ../prop.expect &&
207 test_propget svn:ignore ./nested ../prop.expect &&
208 test_propget svn:ignore .././deeply/nested ../prop.expect
209 '
Benoit Sigoure15153452007-10-16 16:36:50 +0200210
Benoit Sigoure51e057c2007-10-16 16:36:51 +0200211cat >prop.expect <<\EOF
212Properties on '.':
213 svn:entry:committed-date
214 svn:entry:committed-rev
215 svn:entry:last-author
216 svn:entry:uuid
217 svn:ignore
218EOF
219cat >prop2.expect <<\EOF
220Properties on 'nested/directory/.keep':
221 svn:entry:committed-date
222 svn:entry:committed-rev
223 svn:entry:last-author
224 svn:entry:uuid
225EOF
226
227test_expect_success 'test proplist' "
Matthew DeVoreb00b6ac2018-10-05 14:54:06 -0700228 git svn proplist . >actual &&
229 cmp prop.expect actual &&
230
231 git svn proplist nested/directory/.keep >actual &&
232 cmp prop2.expect actual
Benoit Sigoure51e057c2007-10-16 16:36:51 +0200233 "
234
Eric Wong36f5b1f2006-05-23 19:23:41 -0700235test_done