git-svn: t0000: add -f flag to checkout
[git.git] / contrib / git-svn / t / t0000-contrib-git-svn.sh
1 #!/bin/sh
2 #
3 # Copyright (c) 2006 Eric Wong
4 #
5
6 test_description='git-svn tests'
7 . ./lib-git-svn.sh
8
9 mkdir import
10 cd import
11
12 echo foo > foo
13 ln -s foo foo.link
14 mkdir -p dir/a/b/c/d/e
15 echo 'deep dir' > dir/a/b/c/d/e/file
16 mkdir -p bar
17 echo 'zzz' > bar/zzz
18 echo '#!/bin/sh' > exec.sh
19 chmod +x exec.sh
20 svn import -m 'import for git-svn' . "$svnrepo" >/dev/null
21
22 cd ..
23 rm -rf import
24
25 test_expect_success \
26     'initialize git-svn' \
27     "git-svn init $svnrepo"
28
29 test_expect_success \
30     'import an SVN revision into git' \
31     'git-svn fetch'
32
33
34 name='try a deep --rmdir with a commit'
35 git checkout -f -b mybranch remotes/git-svn
36 mv dir/a/b/c/d/e/file dir/file
37 cp dir/file file
38 git update-index --add --remove dir/a/b/c/d/e/file dir/file file
39 git commit -m "$name"
40
41 test_expect_success "$name" \
42     "git-svn commit --find-copies-harder --rmdir remotes/git-svn..mybranch &&
43      test -d $SVN_TREE/dir && test ! -d $SVN_TREE/dir/a"
44
45
46 name='detect node change from file to directory #1'
47 mkdir dir/new_file
48 mv dir/file dir/new_file/file
49 mv dir/new_file dir/file
50 git update-index --remove dir/file
51 git update-index --add dir/file/file
52 git commit -m "$name"
53
54 test_expect_code 1 "$name" \
55     'git-svn commit --find-copies-harder --rmdir remotes/git-svn..mybranch' \
56     || true
57
58
59 name='detect node change from directory to file #1'
60 rm -rf dir $GIT_DIR/index
61 git checkout -f -b mybranch2 remotes/git-svn
62 mv bar/zzz zzz
63 rm -rf bar
64 mv zzz bar
65 git update-index --remove -- bar/zzz
66 git update-index --add -- bar
67 git commit -m "$name"
68
69 test_expect_code 1 "$name" \
70     'git-svn commit --find-copies-harder --rmdir remotes/git-svn..mybranch2' \
71     || true
72
73
74 name='detect node change from file to directory #2'
75 rm -f $GIT_DIR/index
76 git checkout -f -b mybranch3 remotes/git-svn
77 rm bar/zzz
78 git-update-index --remove bar/zzz
79 mkdir bar/zzz
80 echo yyy > bar/zzz/yyy
81 git-update-index --add bar/zzz/yyy
82 git commit -m "$name"
83
84 test_expect_code 1 "$name" \
85     'git-svn commit --find-copies-harder --rmdir remotes/git-svn..mybranch3' \
86     || true
87
88
89 name='detect node change from directory to file #2'
90 rm -f $GIT_DIR/index
91 git checkout -f -b mybranch4 remotes/git-svn
92 rm -rf dir
93 git update-index --remove -- dir/file
94 touch dir
95 echo asdf > dir
96 git update-index --add -- dir
97 git commit -m "$name"
98
99 test_expect_code 1 "$name" \
100     'git-svn commit --find-copies-harder --rmdir remotes/git-svn..mybranch4' \
101     || true
102
103
104 name='remove executable bit from a file'
105 rm -f $GIT_DIR/index
106 git checkout -f -b mybranch5 remotes/git-svn
107 chmod -x exec.sh
108 git update-index exec.sh
109 git commit -m "$name"
110
111 test_expect_success "$name" \
112     "git-svn commit --find-copies-harder --rmdir remotes/git-svn..mybranch5 &&
113      test ! -x $SVN_TREE/exec.sh"
114
115
116 name='add executable bit back file'
117 chmod +x exec.sh
118 git update-index exec.sh
119 git commit -m "$name"
120
121 test_expect_success "$name" \
122     "git-svn commit --find-copies-harder --rmdir remotes/git-svn..mybranch5 &&
123      test -x $SVN_TREE/exec.sh"
124
125
126
127 name='executable file becomes a symlink to bar/zzz (file)'
128 rm exec.sh
129 ln -s bar/zzz exec.sh
130 git update-index exec.sh
131 git commit -m "$name"
132
133 test_expect_success "$name" \
134     "git-svn commit --find-copies-harder --rmdir remotes/git-svn..mybranch5 &&
135      test -L $SVN_TREE/exec.sh"
136
137
138
139 name='new symlink is added to a file that was also just made executable'
140 chmod +x bar/zzz
141 ln -s bar/zzz exec-2.sh
142 git update-index --add bar/zzz exec-2.sh
143 git commit -m "$name"
144
145 test_expect_success "$name" \
146     "git-svn commit --find-copies-harder --rmdir remotes/git-svn..mybranch5 &&
147      test -x $SVN_TREE/bar/zzz &&
148      test -L $SVN_TREE/exec-2.sh"
149
150
151
152 name='modify a symlink to become a file'
153 git help > help || true
154 rm exec-2.sh
155 cp help exec-2.sh
156 git update-index exec-2.sh
157 git commit -m "$name"
158
159 test_expect_success "$name" \
160     "git-svn commit --find-copies-harder --rmdir remotes/git-svn..mybranch5 &&
161      test -f $SVN_TREE/exec-2.sh &&
162      test ! -L $SVN_TREE/exec-2.sh &&
163      diff -u help $SVN_TREE/exec-2.sh"
164
165
166
167 name='test fetch functionality (svn => git) with alternate GIT_SVN_ID'
168 GIT_SVN_ID=alt
169 export GIT_SVN_ID
170 test_expect_success "$name" \
171     "git-svn init $svnrepo && git-svn fetch &&
172      git-rev-list --pretty=raw remotes/git-svn | grep ^tree | uniq > a &&
173      git-rev-list --pretty=raw remotes/alt | grep ^tree | uniq > b &&
174      diff -u a b"
175
176 test_done
177