##// END OF EJS Templates
tests: use double quote to quote arguments in hook for portability...
FUJIWARA Katsunori -
r24838:b2c1ff96 stable
parent child Browse files
Show More
@@ -1,52 +1,52 b''
1 Corrupt an hg repo with a pull started during an aborted commit
1 Corrupt an hg repo with a pull started during an aborted commit
2 Create two repos, so that one of them can pull from the other one.
2 Create two repos, so that one of them can pull from the other one.
3
3
4 $ hg init source
4 $ hg init source
5 $ cd source
5 $ cd source
6 $ touch foo
6 $ touch foo
7 $ hg add foo
7 $ hg add foo
8 $ hg ci -m 'add foo'
8 $ hg ci -m 'add foo'
9 $ hg clone . ../corrupted
9 $ hg clone . ../corrupted
10 updating to branch default
10 updating to branch default
11 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
11 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
12 $ echo >> foo
12 $ echo >> foo
13 $ hg ci -m 'change foo'
13 $ hg ci -m 'change foo'
14
14
15 Add a hook to wait 5 seconds and then abort the commit
15 Add a hook to wait 5 seconds and then abort the commit
16
16
17 $ cd ../corrupted
17 $ cd ../corrupted
18 $ echo "[hooks]" >> .hg/hgrc
18 $ echo "[hooks]" >> .hg/hgrc
19 $ echo "pretxncommit = sh -c 'sleep 5; exit 1'" >> .hg/hgrc
19 $ echo 'pretxncommit = sh -c "sleep 5; exit 1"' >> .hg/hgrc
20
20
21 start a commit...
21 start a commit...
22
22
23 $ touch bar
23 $ touch bar
24 $ hg add bar
24 $ hg add bar
25 $ hg ci -m 'add bar' &
25 $ hg ci -m 'add bar' &
26
26
27 ... and start a pull while the commit is still running
27 ... and start a pull while the commit is still running
28
28
29 $ sleep 1
29 $ sleep 1
30 $ hg pull ../source 2>/dev/null
30 $ hg pull ../source 2>/dev/null
31 pulling from ../source
31 pulling from ../source
32 transaction abort!
32 transaction abort!
33 rollback completed
33 rollback completed
34 abort: pretxncommit hook exited with status 1
34 abort: pretxncommit hook exited with status 1
35 searching for changes
35 searching for changes
36 adding changesets
36 adding changesets
37 adding manifests
37 adding manifests
38 adding file changes
38 adding file changes
39 added 1 changesets with 1 changes to 1 files
39 added 1 changesets with 1 changes to 1 files
40 (run 'hg update' to get a working copy)
40 (run 'hg update' to get a working copy)
41
41
42 see what happened
42 see what happened
43
43
44 $ wait
44 $ wait
45 $ hg verify
45 $ hg verify
46 checking changesets
46 checking changesets
47 checking manifests
47 checking manifests
48 crosschecking files in changesets and manifests
48 crosschecking files in changesets and manifests
49 checking files
49 checking files
50 1 files, 2 changesets, 2 total revisions
50 1 files, 2 changesets, 2 total revisions
51
51
52 $ cd ..
52 $ cd ..
@@ -1,139 +1,139 b''
1 Verify that pending changesets are seen by pretxn* hooks but not by other
1 Verify that pending changesets are seen by pretxn* hooks but not by other
2 processes that access the destination repo while the hooks are running.
2 processes that access the destination repo while the hooks are running.
3
3
4 The hooks (python and external) both reject changesets after some think time,
4 The hooks (python and external) both reject changesets after some think time,
5 during which another process runs pull. Each hook creates a file ('notify') to
5 during which another process runs pull. Each hook creates a file ('notify') to
6 indicate to the controlling process that it is running; the process removes the
6 indicate to the controlling process that it is running; the process removes the
7 file to indicate the hook can terminate.
7 file to indicate the hook can terminate.
8
8
9 init env vars
9 init env vars
10
10
11 $ d=`pwd`
11 $ d=`pwd`
12 $ maxwait=20
12 $ maxwait=20
13
13
14 utility to run the test - start a push in the background and run pull
14 utility to run the test - start a push in the background and run pull
15
15
16 $ dotest() {
16 $ dotest() {
17 > rm -f notify
17 > rm -f notify
18 > printf 'push '; hg -R child-push tip --template '{node}\n'
18 > printf 'push '; hg -R child-push tip --template '{node}\n'
19 > hg -R child-push -q push > push.out 2>&1 &
19 > hg -R child-push -q push > push.out 2>&1 &
20 >
20 >
21 > # wait for hook to create the notify file
21 > # wait for hook to create the notify file
22 > i=$maxwait
22 > i=$maxwait
23 > while [ ! -f notify -a $i != 0 ]; do
23 > while [ ! -f notify -a $i != 0 ]; do
24 > sleep 1
24 > sleep 1
25 > i=`expr $i - 1`
25 > i=`expr $i - 1`
26 > done
26 > done
27 >
27 >
28 > # run pull
28 > # run pull
29 > hg -R child-pull -q pull
29 > hg -R child-pull -q pull
30 > rc=$?
30 > rc=$?
31 >
31 >
32 > # tell hook to finish; notify should exist.
32 > # tell hook to finish; notify should exist.
33 > rm notify
33 > rm notify
34 > wait
34 > wait
35 >
35 >
36 > cat push.out
36 > cat push.out
37 > printf 'pull '; hg -R child-pull tip --template '{node}\n'
37 > printf 'pull '; hg -R child-pull tip --template '{node}\n'
38 > return $rc
38 > return $rc
39 > }
39 > }
40
40
41 python hook
41 python hook
42
42
43 $ cat <<EOF > reject.py
43 $ cat <<EOF > reject.py
44 > import os, time
44 > import os, time
45 > from mercurial import ui, localrepo
45 > from mercurial import ui, localrepo
46 > def rejecthook(ui, repo, hooktype, node, **opts):
46 > def rejecthook(ui, repo, hooktype, node, **opts):
47 > ui.write('hook %s\\n' % repo['tip'].hex())
47 > ui.write('hook %s\\n' % repo['tip'].hex())
48 > # create the notify file so caller knows we're running
48 > # create the notify file so caller knows we're running
49 > fpath = os.path.join('$d', 'notify')
49 > fpath = os.path.join('$d', 'notify')
50 > f = open(fpath, 'w')
50 > f = open(fpath, 'w')
51 > f.close()
51 > f.close()
52 > # wait for ack - caller should delete the notify file
52 > # wait for ack - caller should delete the notify file
53 > i = $maxwait
53 > i = $maxwait
54 > while os.path.exists(fpath) and i > 0:
54 > while os.path.exists(fpath) and i > 0:
55 > time.sleep(1)
55 > time.sleep(1)
56 > i -= 1
56 > i -= 1
57 > return True # reject the changesets
57 > return True # reject the changesets
58 > EOF
58 > EOF
59
59
60 external hook
60 external hook
61
61
62 $ cat <<EOF > reject.sh
62 $ cat <<EOF > reject.sh
63 > printf 'hook '; hg tip --template '{node}\\n'
63 > printf 'hook '; hg tip --template '{node}\\n'
64 > # create the notify file so caller knows we're running
64 > # create the notify file so caller knows we're running
65 > fpath=$d/notify
65 > fpath=$d/notify
66 > touch \$fpath
66 > touch \$fpath
67 > # wait for ack - caller should delete the notify file
67 > # wait for ack - caller should delete the notify file
68 > i=$maxwait
68 > i=$maxwait
69 > while [ -f \$fpath -a \$i != 0 ]; do
69 > while [ -f \$fpath -a \$i != 0 ]; do
70 > sleep 1
70 > sleep 1
71 > i=\`expr \$i - 1\`
71 > i=\`expr \$i - 1\`
72 > done
72 > done
73 > exit 1 # reject the changesets
73 > exit 1 # reject the changesets
74 > EOF
74 > EOF
75
75
76 create repos
76 create repos
77
77
78 $ hg init parent
78 $ hg init parent
79 $ hg clone -q parent child-push
79 $ hg clone -q parent child-push
80 $ hg clone -q parent child-pull
80 $ hg clone -q parent child-pull
81 $ echo a > child-push/a
81 $ echo a > child-push/a
82 $ hg -R child-push add child-push/a
82 $ hg -R child-push add child-push/a
83 $ hg -R child-push commit -m a -d '1000000 0'
83 $ hg -R child-push commit -m a -d '1000000 0'
84
84
85 test python hook
85 test python hook
86
86
87 $ cat <<EOF > parent/.hg/hgrc
87 $ cat <<EOF > parent/.hg/hgrc
88 > [extensions]
88 > [extensions]
89 > reject = $d/reject.py
89 > reject = $d/reject.py
90 > [hooks]
90 > [hooks]
91 > pretxnchangegroup = python:reject.rejecthook
91 > pretxnchangegroup = python:reject.rejecthook
92 > EOF
92 > EOF
93
93
94 $ dotest
94 $ dotest
95 push 29b62aeb769fdf78d8d9c5f28b017f76d7ef824b
95 push 29b62aeb769fdf78d8d9c5f28b017f76d7ef824b
96 hook 29b62aeb769fdf78d8d9c5f28b017f76d7ef824b
96 hook 29b62aeb769fdf78d8d9c5f28b017f76d7ef824b
97 transaction abort!
97 transaction abort!
98 rollback completed
98 rollback completed
99 abort: pretxnchangegroup hook failed
99 abort: pretxnchangegroup hook failed
100 pull 0000000000000000000000000000000000000000
100 pull 0000000000000000000000000000000000000000
101
101
102 test external hook
102 test external hook
103
103
104 $ cat <<EOF > parent/.hg/hgrc
104 $ cat <<EOF > parent/.hg/hgrc
105 > [hooks]
105 > [hooks]
106 > pretxnchangegroup = sh $d/reject.sh
106 > pretxnchangegroup = sh $d/reject.sh
107 > EOF
107 > EOF
108
108
109 $ dotest
109 $ dotest
110 push 29b62aeb769fdf78d8d9c5f28b017f76d7ef824b
110 push 29b62aeb769fdf78d8d9c5f28b017f76d7ef824b
111 hook 29b62aeb769fdf78d8d9c5f28b017f76d7ef824b
111 hook 29b62aeb769fdf78d8d9c5f28b017f76d7ef824b
112 transaction abort!
112 transaction abort!
113 rollback completed
113 rollback completed
114 abort: pretxnchangegroup hook exited with status 1
114 abort: pretxnchangegroup hook exited with status 1
115 pull 0000000000000000000000000000000000000000
115 pull 0000000000000000000000000000000000000000
116
116
117 Test that pending on transaction without changegroup see the normal changegroup(
117 Test that pending on transaction without changegroup see the normal changegroup(
118 (issue4609)
118 (issue4609)
119
119
120 $ cat <<EOF > parent/.hg/hgrc
120 $ cat <<EOF > parent/.hg/hgrc
121 > [hooks]
121 > [hooks]
122 > pretxnchangegroup=
122 > pretxnchangegroup=
123 > pretxnclose = hg tip -T 'tip: {node|short}\n'
123 > pretxnclose = hg tip -T "tip: {node|short}\n"
124 > [phases]
124 > [phases]
125 > publishing=False
125 > publishing=False
126 > EOF
126 > EOF
127
127
128 setup
128 setup
129
129
130 $ cd parent
130 $ cd parent
131 $ echo a > a
131 $ echo a > a
132 $ hg add a
132 $ hg add a
133 $ hg commit -m a
133 $ hg commit -m a
134 tip: cb9a9f314b8b
134 tip: cb9a9f314b8b
135
135
136 actual test
136 actual test
137
137
138 $ hg phase --public .
138 $ hg phase --public .
139 tip: cb9a9f314b8b
139 tip: cb9a9f314b8b
General Comments 0
You need to be logged in to leave comments. Login now