unit-tests: do not mistake `.pdb` files for being executable
[git.git] / t / t9164-git-svn-dcommit-concurrent.sh
blobc8e6c0733f41cf90a41941a3ad3550efb7ea56f1
1 #!/bin/sh
3 # Copyright (c) 2012 Robert Luberda
6 test_description='concurrent git svn dcommit'
8 . ./lib-git-svn.sh
12 test_expect_success 'setup svn repository' '
13 svn_cmd checkout "$svnrepo" work.svn &&
15 cd work.svn &&
16 echo >file && echo > auto_updated_file &&
17 svn_cmd add file auto_updated_file &&
18 svn_cmd commit -m "initial commit"
19 ) &&
20 svn_cmd checkout "$svnrepo" work-auto-commits.svn
22 N=0
23 next_N()
25 N=$(( $N + 1 ))
28 # Setup SVN repository hooks to emulate SVN failures or concurrent commits
29 # The function adds
30 # either pre-commit hook, which causes SVN commit given in second argument
31 # to fail
32 # or post-commit hook, which creates a new commit (a new line added to
33 # auto_updated_file) after given SVN commit
34 # The first argument contains a type of the hook
35 # The second argument contains a number (not SVN revision) of commit
36 # the hook should be applied for (each time the hook is run, the given
37 # number is decreased by one until it gets 0, in which case the hook
38 # will execute its real action)
39 setup_hook()
41 hook_type="$1" # "pre-commit" or "post-commit"
42 skip_revs="$2"
43 [ "$hook_type" = "pre-commit" ] ||
44 [ "$hook_type" = "post-commit" ] ||
45 { echo "ERROR: invalid argument ($hook_type)" \
46 "passed to setup_hook" >&2 ; return 1; }
47 echo "cnt=$skip_revs" > "$hook_type-counter"
48 rm -f "$rawsvnrepo/hooks/"*-commit # drop previous hooks
49 hook="$rawsvnrepo/hooks/$hook_type"
50 cat > "$hook" <<- 'EOF1'
51 #!/bin/sh
52 set -e
53 cd "$1/.." # "$1" is repository location
54 exec >> svn-hook.log 2>&1
55 hook="$(basename "$0")"
56 echo "*** Executing $hook $@"
57 set -x
58 . ./$hook-counter
59 cnt="$(($cnt - 1))"
60 echo "cnt=$cnt" > ./$hook-counter
61 [ "$cnt" = "0" ] || exit 0
62 EOF1
63 if [ "$hook_type" = "pre-commit" ]; then
64 echo "echo 'commit disallowed' >&2; exit 1" >>"$hook"
65 else
66 echo "PATH=\"$PATH\"; export PATH" >>"$hook"
67 echo "svnconf=\"$svnconf\"" >>"$hook"
68 cat >>"$hook" <<- 'EOF2'
69 cd work-auto-commits.svn
70 svn up --config-dir "$svnconf"
71 echo "$$" >> auto_updated_file
72 svn commit --config-dir "$svnconf" \
73 -m "auto-committing concurrent change"
74 exit 0
75 EOF2
77 chmod 755 "$hook"
80 check_contents()
82 gitdir="$1"
83 (cd ../work.svn && svn_cmd up) &&
84 test_cmp file ../work.svn/file &&
85 test_cmp auto_updated_file ../work.svn/auto_updated_file
88 test_expect_success 'check if post-commit hook creates a concurrent commit' '
89 setup_hook post-commit 1 &&
91 cd work.svn &&
92 cp auto_updated_file au_file_saved &&
93 echo 1 >> file &&
94 svn_cmd commit -m "changing file" &&
95 svn_cmd up &&
96 ! test_cmp auto_updated_file au_file_saved
100 test_expect_success 'check if pre-commit hook fails' '
101 setup_hook pre-commit 2 &&
103 cd work.svn &&
104 echo 2 >> file &&
105 svn_cmd commit -m "changing file once again" &&
106 echo 3 >> file &&
107 ! svn_cmd commit -m "this commit should fail" &&
108 svn_cmd revert file
112 test_expect_success 'dcommit error handling' '
113 setup_hook pre-commit 2 &&
114 next_N && git svn clone "$svnrepo" work$N.git &&
116 cd work$N.git &&
117 echo 1 >> file && git commit -am "commit change $N.1" &&
118 echo 2 >> file && git commit -am "commit change $N.2" &&
119 echo 3 >> file && git commit -am "commit change $N.3" &&
120 # should fail to dcommit 2nd and 3rd change
121 # but still should leave the repository in reasonable state
122 test_must_fail git svn dcommit &&
123 git update-index --refresh &&
124 git show HEAD~2 | grep -q git-svn-id &&
125 ! git show HEAD~1 | grep -q git-svn-id &&
126 ! git show HEAD | grep -q git-svn-id
130 test_expect_success 'dcommit concurrent change in non-changed file' '
131 setup_hook post-commit 2 &&
132 next_N && git svn clone "$svnrepo" work$N.git &&
134 cd work$N.git &&
135 echo 1 >> file && git commit -am "commit change $N.1" &&
136 echo 2 >> file && git commit -am "commit change $N.2" &&
137 echo 3 >> file && git commit -am "commit change $N.3" &&
138 # should rebase and leave the repository in reasonable state
139 git svn dcommit &&
140 git update-index --refresh &&
141 check_contents &&
142 git show HEAD~3 | grep -q git-svn-id &&
143 git show HEAD~2 | grep -q git-svn-id &&
144 git show HEAD~1 | grep -q auto-committing &&
145 git show HEAD | grep -q git-svn-id
149 # An utility function used in the following test
150 delete_first_line()
152 file="$1" &&
153 sed 1d < "$file" > "${file}.tmp" &&
154 rm "$file" &&
155 mv "${file}.tmp" "$file"
158 test_expect_success 'dcommit concurrent non-conflicting change' '
159 setup_hook post-commit 2 &&
160 next_N && git svn clone "$svnrepo" work$N.git &&
162 cd work$N.git &&
163 cat file >> auto_updated_file &&
164 git commit -am "commit change $N.1" &&
165 delete_first_line auto_updated_file &&
166 git commit -am "commit change $N.2" &&
167 delete_first_line auto_updated_file &&
168 git commit -am "commit change $N.3" &&
169 # should rebase and leave the repository in reasonable state
170 git svn dcommit &&
171 git update-index --refresh &&
172 check_contents &&
173 git show HEAD~3 | grep -q git-svn-id &&
174 git show HEAD~2 | grep -q git-svn-id &&
175 git show HEAD~1 | grep -q auto-committing &&
176 git show HEAD | grep -q git-svn-id
180 test_expect_success 'dcommit --no-rebase concurrent non-conflicting change' '
181 setup_hook post-commit 2 &&
182 next_N && git svn clone "$svnrepo" work$N.git &&
184 cd work$N.git &&
185 cat file >> auto_updated_file &&
186 git commit -am "commit change $N.1" &&
187 delete_first_line auto_updated_file &&
188 git commit -am "commit change $N.2" &&
189 delete_first_line auto_updated_file &&
190 git commit -am "commit change $N.3" &&
191 # should fail as rebase is needed
192 test_must_fail git svn dcommit --no-rebase &&
193 # but should leave HEAD unchanged
194 git update-index --refresh &&
195 ! git show HEAD~2 | grep -q git-svn-id &&
196 ! git show HEAD~1 | grep -q git-svn-id &&
197 ! git show HEAD | grep -q git-svn-id
201 test_expect_success 'dcommit fails on concurrent conflicting change' '
202 setup_hook post-commit 1 &&
203 next_N && git svn clone "$svnrepo" work$N.git &&
205 cd work$N.git &&
206 echo a >> file &&
207 git commit -am "commit change $N.1" &&
208 echo b >> auto_updated_file &&
209 git commit -am "commit change $N.2" &&
210 echo c >> auto_updated_file &&
211 git commit -am "commit change $N.3" &&
212 test_must_fail git svn dcommit && # rebase should fail
213 test_must_fail git update-index --refresh
217 test_done