3 # Copyright (c) 2012 Robert Luberda
6 test_description
='concurrent git svn dcommit'
12 test_expect_success
'setup svn repository' '
13 svn_cmd checkout "$svnrepo" work.svn &&
16 echo >file && echo > auto_updated_file &&
17 svn_cmd add file auto_updated_file &&
18 svn_cmd commit -m "initial commit"
20 svn_cmd checkout "$svnrepo" work-auto-commits.svn
28 # Setup SVN repository hooks to emulate SVN failures or concurrent commits
30 # either pre-commit hook, which causes SVN commit given in second argument
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)
41 hook_type
="$1" # "pre-commit" or "post-commit"
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'
53 cd "$1/.." # "$1" is repository location
54 exec >> svn-hook.log 2>&1
55 hook="$(basename "$0")"
56 echo "*** Executing $hook $@"
60 echo "cnt
=$cnt" > ./$hook-counter
61 [ "$cnt" = "0" ] || exit 0
63 if [ "$hook_type" = "pre-commit
" ]; then
64 echo "echo 'commit disallowed' >&2; exit 1" >>"$hook"
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
"
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 &&
92 cp auto_updated_file au_file_saved &&
94 svn_cmd commit -m "changing
file" &&
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 &&
105 svn_cmd commit -m "changing
file once again
" &&
107 ! svn_cmd commit -m "this commit should fail
" &&
112 test_expect_success 'dcommit error handling' '
113 setup_hook pre-commit 2 &&
114 next_N && git svn clone "$svnrepo" 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 &&
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
140 git update-index --refresh &&
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
153 sed 1d < "$file" > "${file}.tmp
" &&
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 &&
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
171 git update-index --refresh &&
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 &&
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 &&
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