Show More
This diff has been collapsed as it changes many lines, (608 lines changed) Show them Hide them | |||
@@ -1,273 +1,465 b'' | |||
|
1 | #!/bin/sh | |
|
2 | ||
|
3 | cp "$TESTDIR"/printenv.py . | |
|
1 | $ cp "$TESTDIR"/printenv.py . | |
|
4 | 2 | |
|
5 | 3 | # commit hooks can see env vars |
|
6 | hg init a | |
|
7 | cd a | |
|
8 | echo "[hooks]" > .hg/hgrc | |
|
9 | echo 'commit = unset HG_LOCAL HG_TAG; python ../printenv.py commit' >> .hg/hgrc | |
|
10 | echo 'commit.b = unset HG_LOCAL HG_TAG; python ../printenv.py commit.b' >> .hg/hgrc | |
|
11 | echo 'precommit = unset HG_LOCAL HG_NODE HG_TAG; python ../printenv.py precommit' >> .hg/hgrc | |
|
12 | echo 'pretxncommit = unset HG_LOCAL HG_TAG; python ../printenv.py pretxncommit' >> .hg/hgrc | |
|
13 | echo 'pretxncommit.tip = hg -q tip' >> .hg/hgrc | |
|
14 | echo 'pre-identify = python ../printenv.py pre-identify 1' >> .hg/hgrc | |
|
15 | echo 'pre-cat = python ../printenv.py pre-cat' >> .hg/hgrc | |
|
16 | echo 'post-cat = python ../printenv.py post-cat' >> .hg/hgrc | |
|
17 | echo a > a | |
|
18 | hg add a | |
|
19 | hg commit -m a -d "1000000 0" | |
|
20 | 4 | |
|
21 | hg clone . ../b | |
|
22 | cd ../b | |
|
5 | $ hg init a | |
|
6 | $ cd a | |
|
7 | $ echo "[hooks]" > .hg/hgrc | |
|
8 | $ echo 'commit = unset HG_LOCAL HG_TAG; python ../printenv.py commit' >> .hg/hgrc | |
|
9 | $ echo 'commit.b = unset HG_LOCAL HG_TAG; python ../printenv.py commit.b' >> .hg/hgrc | |
|
10 | $ echo 'precommit = unset HG_LOCAL HG_NODE HG_TAG; python ../printenv.py precommit' >> .hg/hgrc | |
|
11 | $ echo 'pretxncommit = unset HG_LOCAL HG_TAG; python ../printenv.py pretxncommit' >> .hg/hgrc | |
|
12 | $ echo 'pretxncommit.tip = hg -q tip' >> .hg/hgrc | |
|
13 | $ echo 'pre-identify = python ../printenv.py pre-identify 1' >> .hg/hgrc | |
|
14 | $ echo 'pre-cat = python ../printenv.py pre-cat' >> .hg/hgrc | |
|
15 | $ echo 'post-cat = python ../printenv.py post-cat' >> .hg/hgrc | |
|
16 | $ echo a > a | |
|
17 | $ hg add a | |
|
18 | $ hg commit -m a -d "1000000 0" | |
|
19 | precommit hook: HG_PARENT1=0000000000000000000000000000000000000000 | |
|
20 | pretxncommit hook: HG_NODE=29b62aeb769fdf78d8d9c5f28b017f76d7ef824b HG_PARENT1=0000000000000000000000000000000000000000 HG_PENDING=$HGTMP/test-hook.t/a | |
|
21 | 0:29b62aeb769f | |
|
22 | commit hook: HG_NODE=29b62aeb769fdf78d8d9c5f28b017f76d7ef824b HG_PARENT1=0000000000000000000000000000000000000000 | |
|
23 | commit.b hook: HG_NODE=29b62aeb769fdf78d8d9c5f28b017f76d7ef824b HG_PARENT1=0000000000000000000000000000000000000000 | |
|
24 | ||
|
25 | $ hg clone . ../b | |
|
26 | updating to branch default | |
|
27 | 1 files updated, 0 files merged, 0 files removed, 0 files unresolved | |
|
28 | $ cd ../b | |
|
23 | 29 | |
|
24 | 30 | # changegroup hooks can see env vars |
|
25 | echo '[hooks]' > .hg/hgrc | |
|
26 | echo 'prechangegroup = python ../printenv.py prechangegroup' >> .hg/hgrc | |
|
27 | echo 'changegroup = python ../printenv.py changegroup' >> .hg/hgrc | |
|
28 |
echo ' |
|
|
31 | ||
|
32 | $ echo '[hooks]' > .hg/hgrc | |
|
33 | $ echo 'prechangegroup = python ../printenv.py prechangegroup' >> .hg/hgrc | |
|
34 | $ echo 'changegroup = python ../printenv.py changegroup' >> .hg/hgrc | |
|
35 | $ echo 'incoming = python ../printenv.py incoming' >> .hg/hgrc | |
|
29 | 36 | |
|
30 | 37 | # pretxncommit and commit hooks can see both parents of merge |
|
31 | cd ../a | |
|
32 | echo b >> a | |
|
33 | hg commit -m a1 -d "1 0" | |
|
34 | hg update -C 0 | |
|
35 | echo b > b | |
|
36 | hg add b | |
|
37 | hg commit -m b -d '1 0' | |
|
38 | hg merge 1 | |
|
39 | hg commit -m merge -d '2 0' | |
|
38 | ||
|
39 | $ cd ../a | |
|
40 | $ echo b >> a | |
|
41 | $ hg commit -m a1 -d "1 0" | |
|
42 | precommit hook: HG_PARENT1=29b62aeb769fdf78d8d9c5f28b017f76d7ef824b | |
|
43 | pretxncommit hook: HG_NODE=b702efe9688826e3a91283852b328b84dbf37bc2 HG_PARENT1=29b62aeb769fdf78d8d9c5f28b017f76d7ef824b HG_PENDING=$HGTMP/test-hook.t/a | |
|
44 | 1:b702efe96888 | |
|
45 | commit hook: HG_NODE=b702efe9688826e3a91283852b328b84dbf37bc2 HG_PARENT1=29b62aeb769fdf78d8d9c5f28b017f76d7ef824b | |
|
46 | commit.b hook: HG_NODE=b702efe9688826e3a91283852b328b84dbf37bc2 HG_PARENT1=29b62aeb769fdf78d8d9c5f28b017f76d7ef824b | |
|
47 | $ hg update -C 0 | |
|
48 | 1 files updated, 0 files merged, 0 files removed, 0 files unresolved | |
|
49 | $ echo b > b | |
|
50 | $ hg add b | |
|
51 | $ hg commit -m b -d '1 0' | |
|
52 | precommit hook: HG_PARENT1=29b62aeb769fdf78d8d9c5f28b017f76d7ef824b | |
|
53 | pretxncommit hook: HG_NODE=1324a5531bac09b329c3845d35ae6a7526874edb HG_PARENT1=29b62aeb769fdf78d8d9c5f28b017f76d7ef824b HG_PENDING=$HGTMP/test-hook.t/a | |
|
54 | 2:1324a5531bac | |
|
55 | commit hook: HG_NODE=1324a5531bac09b329c3845d35ae6a7526874edb HG_PARENT1=29b62aeb769fdf78d8d9c5f28b017f76d7ef824b | |
|
56 | commit.b hook: HG_NODE=1324a5531bac09b329c3845d35ae6a7526874edb HG_PARENT1=29b62aeb769fdf78d8d9c5f28b017f76d7ef824b | |
|
57 | created new head | |
|
58 | $ hg merge 1 | |
|
59 | 1 files updated, 0 files merged, 0 files removed, 0 files unresolved | |
|
60 | (branch merge, don't forget to commit) | |
|
61 | $ hg commit -m merge -d '2 0' | |
|
62 | precommit hook: HG_PARENT1=1324a5531bac09b329c3845d35ae6a7526874edb HG_PARENT2=b702efe9688826e3a91283852b328b84dbf37bc2 | |
|
63 | pretxncommit hook: HG_NODE=4c52fb2e402287dd5dc052090682536c8406c321 HG_PARENT1=1324a5531bac09b329c3845d35ae6a7526874edb HG_PARENT2=b702efe9688826e3a91283852b328b84dbf37bc2 HG_PENDING=$HGTMP/test-hook.t/a | |
|
64 | 3:4c52fb2e4022 | |
|
65 | commit hook: HG_NODE=4c52fb2e402287dd5dc052090682536c8406c321 HG_PARENT1=1324a5531bac09b329c3845d35ae6a7526874edb HG_PARENT2=b702efe9688826e3a91283852b328b84dbf37bc2 | |
|
66 | commit.b hook: HG_NODE=4c52fb2e402287dd5dc052090682536c8406c321 HG_PARENT1=1324a5531bac09b329c3845d35ae6a7526874edb HG_PARENT2=b702efe9688826e3a91283852b328b84dbf37bc2 | |
|
40 | 67 | |
|
41 | 68 | # test generic hooks |
|
42 | hg id | |
|
43 | hg cat b | |
|
69 | ||
|
70 | $ hg id | |
|
71 | pre-identify hook: HG_ARGS=id HG_OPTS={'tags': None, 'rev': '', 'num': None, 'branch': None, 'id': None} HG_PATS=[] | |
|
72 | warning: pre-identify hook exited with status 1 | |
|
73 | $ hg cat b | |
|
74 | pre-cat hook: HG_ARGS=cat b HG_OPTS={'rev': '', 'decode': None, 'exclude': [], 'output': '', 'include': []} HG_PATS=['b'] | |
|
75 | post-cat hook: HG_ARGS=cat b HG_OPTS={'rev': '', 'decode': None, 'exclude': [], 'output': '', 'include': []} HG_PATS=['b'] HG_RESULT=0 | |
|
76 | b | |
|
44 | 77 | |
|
45 | cd ../b | |
|
46 | hg pull ../a | |
|
78 | $ cd ../b | |
|
79 | $ hg pull ../a | |
|
80 | prechangegroup hook: HG_SOURCE=pull HG_URL=file: | |
|
81 | changegroup hook: HG_NODE=b702efe9688826e3a91283852b328b84dbf37bc2 HG_SOURCE=pull HG_URL=file: | |
|
82 | incoming hook: HG_NODE=b702efe9688826e3a91283852b328b84dbf37bc2 HG_SOURCE=pull HG_URL=file: | |
|
83 | incoming hook: HG_NODE=1324a5531bac09b329c3845d35ae6a7526874edb HG_SOURCE=pull HG_URL=file: | |
|
84 | incoming hook: HG_NODE=4c52fb2e402287dd5dc052090682536c8406c321 HG_SOURCE=pull HG_URL=file: | |
|
85 | pulling from ../a | |
|
86 | searching for changes | |
|
87 | adding changesets | |
|
88 | adding manifests | |
|
89 | adding file changes | |
|
90 | added 3 changesets with 2 changes to 2 files | |
|
91 | (run 'hg update' to get a working copy) | |
|
47 | 92 | |
|
48 | 93 | # tag hooks can see env vars |
|
49 | cd ../a | |
|
50 | echo 'pretag = python ../printenv.py pretag' >> .hg/hgrc | |
|
51 |
echo 'tag = |
|
|
52 | hg tag -d '3 0' a | |
|
53 |
hg tag - |
|
|
94 | ||
|
95 | $ cd ../a | |
|
96 | $ echo 'pretag = python ../printenv.py pretag' >> .hg/hgrc | |
|
97 | $ echo 'tag = unset HG_PARENT1 HG_PARENT2; python ../printenv.py tag' >> .hg/hgrc | |
|
98 | $ hg tag -d '3 0' a | |
|
99 | pretag hook: HG_LOCAL=0 HG_NODE=4c52fb2e402287dd5dc052090682536c8406c321 HG_TAG=a | |
|
100 | precommit hook: HG_PARENT1=4c52fb2e402287dd5dc052090682536c8406c321 | |
|
101 | pretxncommit hook: HG_NODE=8ea2ef7ad3e8cac946c72f1e0c79d6aebc301198 HG_PARENT1=4c52fb2e402287dd5dc052090682536c8406c321 HG_PENDING=$HGTMP/test-hook.t/a | |
|
102 | 4:8ea2ef7ad3e8 | |
|
103 | commit hook: HG_NODE=8ea2ef7ad3e8cac946c72f1e0c79d6aebc301198 HG_PARENT1=4c52fb2e402287dd5dc052090682536c8406c321 | |
|
104 | commit.b hook: HG_NODE=8ea2ef7ad3e8cac946c72f1e0c79d6aebc301198 HG_PARENT1=4c52fb2e402287dd5dc052090682536c8406c321 | |
|
105 | tag hook: HG_LOCAL=0 HG_NODE=4c52fb2e402287dd5dc052090682536c8406c321 HG_TAG=a | |
|
106 | $ hg tag -l la | |
|
107 | pretag hook: HG_LOCAL=1 HG_NODE=8ea2ef7ad3e8cac946c72f1e0c79d6aebc301198 HG_TAG=la | |
|
108 | tag hook: HG_LOCAL=1 HG_NODE=8ea2ef7ad3e8cac946c72f1e0c79d6aebc301198 HG_TAG=la | |
|
54 | 109 | |
|
55 | 110 | # pretag hook can forbid tagging |
|
56 | echo 'pretag.forbid = python ../printenv.py pretag.forbid 1' >> .hg/hgrc | |
|
57 | hg tag -d '4 0' fa | |
|
58 |
hg tag - |
|
|
111 | ||
|
112 | $ echo 'pretag.forbid = python ../printenv.py pretag.forbid 1' >> .hg/hgrc | |
|
113 | $ hg tag -d '4 0' fa | |
|
114 | pretag hook: HG_LOCAL=0 HG_NODE=8ea2ef7ad3e8cac946c72f1e0c79d6aebc301198 HG_TAG=fa | |
|
115 | pretag.forbid hook: HG_LOCAL=0 HG_NODE=8ea2ef7ad3e8cac946c72f1e0c79d6aebc301198 HG_TAG=fa | |
|
116 | abort: pretag.forbid hook exited with status 1 | |
|
117 | $ hg tag -l fla | |
|
118 | pretag hook: HG_LOCAL=1 HG_NODE=8ea2ef7ad3e8cac946c72f1e0c79d6aebc301198 HG_TAG=fla | |
|
119 | pretag.forbid hook: HG_LOCAL=1 HG_NODE=8ea2ef7ad3e8cac946c72f1e0c79d6aebc301198 HG_TAG=fla | |
|
120 | abort: pretag.forbid hook exited with status 1 | |
|
59 | 121 | |
|
60 | 122 | # pretxncommit hook can see changeset, can roll back txn, changeset |
|
61 | 123 | # no more there after |
|
62 | echo 'pretxncommit.forbid0 = hg tip -q' >> .hg/hgrc | |
|
63 |
echo 'pretxncommit.forbid |
|
|
64 | echo z > z | |
|
65 | hg add z | |
|
66 | hg -q tip | |
|
67 | hg commit -m 'fail' -d '4 0' | |
|
68 | hg -q tip | |
|
124 | ||
|
125 | $ echo 'pretxncommit.forbid0 = hg tip -q' >> .hg/hgrc | |
|
126 | $ echo 'pretxncommit.forbid1 = python ../printenv.py pretxncommit.forbid 1' >> .hg/hgrc | |
|
127 | $ echo z > z | |
|
128 | $ hg add z | |
|
129 | $ hg -q tip | |
|
130 | 4:8ea2ef7ad3e8 | |
|
131 | $ hg commit -m 'fail' -d '4 0' | |
|
132 | precommit hook: HG_PARENT1=8ea2ef7ad3e8cac946c72f1e0c79d6aebc301198 | |
|
133 | pretxncommit hook: HG_NODE=fad284daf8c032148abaffcd745dafeceefceb61 HG_PARENT1=8ea2ef7ad3e8cac946c72f1e0c79d6aebc301198 HG_PENDING=$HGTMP/test-hook.t/a | |
|
134 | 5:fad284daf8c0 | |
|
135 | 5:fad284daf8c0 | |
|
136 | pretxncommit.forbid hook: HG_NODE=fad284daf8c032148abaffcd745dafeceefceb61 HG_PARENT1=8ea2ef7ad3e8cac946c72f1e0c79d6aebc301198 HG_PENDING=$HGTMP/test-hook.t/a | |
|
137 | transaction abort! | |
|
138 | rollback completed | |
|
139 | abort: pretxncommit.forbid1 hook exited with status 1 | |
|
140 | $ hg -q tip | |
|
141 | 4:8ea2ef7ad3e8 | |
|
69 | 142 | |
|
70 | 143 | # precommit hook can prevent commit |
|
71 | echo 'precommit.forbid = python ../printenv.py precommit.forbid 1' >> .hg/hgrc | |
|
72 | hg commit -m 'fail' -d '4 0' | |
|
73 | hg -q tip | |
|
144 | ||
|
145 | $ echo 'precommit.forbid = python ../printenv.py precommit.forbid 1' >> .hg/hgrc | |
|
146 | $ hg commit -m 'fail' -d '4 0' | |
|
147 | precommit hook: HG_PARENT1=8ea2ef7ad3e8cac946c72f1e0c79d6aebc301198 | |
|
148 | precommit.forbid hook: HG_PARENT1=8ea2ef7ad3e8cac946c72f1e0c79d6aebc301198 | |
|
149 | abort: precommit.forbid hook exited with status 1 | |
|
150 | $ hg -q tip | |
|
151 | 4:8ea2ef7ad3e8 | |
|
74 | 152 | |
|
75 | 153 | # preupdate hook can prevent update |
|
76 | echo 'preupdate = python ../printenv.py preupdate' >> .hg/hgrc | |
|
77 | hg update 1 | |
|
154 | ||
|
155 | $ echo 'preupdate = python ../printenv.py preupdate' >> .hg/hgrc | |
|
156 | $ hg update 1 | |
|
157 | preupdate hook: HG_PARENT1=b702efe96888 | |
|
158 | 0 files updated, 0 files merged, 2 files removed, 0 files unresolved | |
|
78 | 159 | |
|
79 | 160 | # update hook |
|
80 | echo 'update = python ../printenv.py update' >> .hg/hgrc | |
|
81 | hg update | |
|
161 | ||
|
162 | $ echo 'update = python ../printenv.py update' >> .hg/hgrc | |
|
163 | $ hg update | |
|
164 | preupdate hook: HG_PARENT1=8ea2ef7ad3e8 | |
|
165 | update hook: HG_ERROR=0 HG_PARENT1=8ea2ef7ad3e8 | |
|
166 | 2 files updated, 0 files merged, 0 files removed, 0 files unresolved | |
|
82 | 167 | |
|
83 | 168 | # prechangegroup hook can prevent incoming changes |
|
84 | cd ../b | |
|
85 | hg -q tip | |
|
86 | echo '[hooks]' > .hg/hgrc | |
|
87 | echo 'prechangegroup.forbid = python ../printenv.py prechangegroup.forbid 1' >> .hg/hgrc | |
|
88 | hg pull ../a | |
|
169 | ||
|
170 | $ cd ../b | |
|
171 | $ hg -q tip | |
|
172 | 3:4c52fb2e4022 | |
|
173 | $ echo '[hooks]' > .hg/hgrc | |
|
174 | $ echo 'prechangegroup.forbid = python ../printenv.py prechangegroup.forbid 1' >> .hg/hgrc | |
|
175 | $ hg pull ../a | |
|
176 | prechangegroup.forbid hook: HG_SOURCE=pull HG_URL=file: | |
|
177 | pulling from ../a | |
|
178 | searching for changes | |
|
179 | abort: prechangegroup.forbid hook exited with status 1 | |
|
89 | 180 | |
|
90 | 181 | # pretxnchangegroup hook can see incoming changes, can roll back txn, |
|
91 | 182 | # incoming changes no longer there after |
|
92 | echo '[hooks]' > .hg/hgrc | |
|
93 | echo 'pretxnchangegroup.forbid0 = hg tip -q' >> .hg/hgrc | |
|
94 |
echo 'pretxnchangegroup.forbid |
|
|
95 | hg pull ../a | |
|
96 | hg -q tip | |
|
183 | ||
|
184 | $ echo '[hooks]' > .hg/hgrc | |
|
185 | $ echo 'pretxnchangegroup.forbid0 = hg tip -q' >> .hg/hgrc | |
|
186 | $ echo 'pretxnchangegroup.forbid1 = python ../printenv.py pretxnchangegroup.forbid 1' >> .hg/hgrc | |
|
187 | $ hg pull ../a | |
|
188 | 4:8ea2ef7ad3e8 | |
|
189 | pretxnchangegroup.forbid hook: HG_NODE=8ea2ef7ad3e8cac946c72f1e0c79d6aebc301198 HG_PENDING=$HGTMP/test-hook.t/b HG_SOURCE=pull HG_URL=file: | |
|
190 | pulling from ../a | |
|
191 | searching for changes | |
|
192 | adding changesets | |
|
193 | adding manifests | |
|
194 | adding file changes | |
|
195 | added 1 changesets with 1 changes to 1 files | |
|
196 | transaction abort! | |
|
197 | rollback completed | |
|
198 | abort: pretxnchangegroup.forbid1 hook exited with status 1 | |
|
199 | $ hg -q tip | |
|
200 | 3:4c52fb2e4022 | |
|
97 | 201 | |
|
98 | 202 | # outgoing hooks can see env vars |
|
99 | rm .hg/hgrc | |
|
100 | echo '[hooks]' > ../a/.hg/hgrc | |
|
101 | echo 'preoutgoing = python ../printenv.py preoutgoing' >> ../a/.hg/hgrc | |
|
102 | echo 'outgoing = python ../printenv.py outgoing' >> ../a/.hg/hgrc | |
|
103 | hg pull ../a | |
|
104 | hg rollback | |
|
203 | ||
|
204 | $ rm .hg/hgrc | |
|
205 | $ echo '[hooks]' > ../a/.hg/hgrc | |
|
206 | $ echo 'preoutgoing = python ../printenv.py preoutgoing' >> ../a/.hg/hgrc | |
|
207 | $ echo 'outgoing = python ../printenv.py outgoing' >> ../a/.hg/hgrc | |
|
208 | $ hg pull ../a | |
|
209 | preoutgoing hook: HG_SOURCE=pull | |
|
210 | outgoing hook: HG_NODE=8ea2ef7ad3e8cac946c72f1e0c79d6aebc301198 HG_SOURCE=pull | |
|
211 | pulling from ../a | |
|
212 | searching for changes | |
|
213 | adding changesets | |
|
214 | adding manifests | |
|
215 | adding file changes | |
|
216 | added 1 changesets with 1 changes to 1 files | |
|
217 | (run 'hg update' to get a working copy) | |
|
218 | $ hg rollback | |
|
219 | rolling back to revision 3 (undo pull) | |
|
105 | 220 | |
|
106 | 221 | # preoutgoing hook can prevent outgoing changes |
|
107 | echo 'preoutgoing.forbid = python ../printenv.py preoutgoing.forbid 1' >> ../a/.hg/hgrc | |
|
108 | hg pull ../a | |
|
222 | ||
|
223 | $ echo 'preoutgoing.forbid = python ../printenv.py preoutgoing.forbid 1' >> ../a/.hg/hgrc | |
|
224 | $ hg pull ../a | |
|
225 | preoutgoing hook: HG_SOURCE=pull | |
|
226 | preoutgoing.forbid hook: HG_SOURCE=pull | |
|
227 | pulling from ../a | |
|
228 | searching for changes | |
|
229 | abort: preoutgoing.forbid hook exited with status 1 | |
|
109 | 230 | |
|
110 | 231 | # outgoing hooks work for local clones |
|
111 | cd .. | |
|
112 | echo '[hooks]' > a/.hg/hgrc | |
|
113 | echo 'preoutgoing = python ../printenv.py preoutgoing' >> a/.hg/hgrc | |
|
114 | echo 'outgoing = python ../printenv.py outgoing' >> a/.hg/hgrc | |
|
115 | hg clone a c | |
|
116 | rm -rf c | |
|
232 | ||
|
233 | $ cd .. | |
|
234 | $ echo '[hooks]' > a/.hg/hgrc | |
|
235 | $ echo 'preoutgoing = python ../printenv.py preoutgoing' >> a/.hg/hgrc | |
|
236 | $ echo 'outgoing = python ../printenv.py outgoing' >> a/.hg/hgrc | |
|
237 | $ hg clone a c | |
|
238 | preoutgoing hook: HG_SOURCE=clone | |
|
239 | outgoing hook: HG_NODE=0000000000000000000000000000000000000000 HG_SOURCE=clone | |
|
240 | updating to branch default | |
|
241 | 3 files updated, 0 files merged, 0 files removed, 0 files unresolved | |
|
242 | $ rm -rf c | |
|
117 | 243 | |
|
118 | 244 | # preoutgoing hook can prevent outgoing changes for local clones |
|
119 | echo 'preoutgoing.forbid = python ../printenv.py preoutgoing.forbid 1' >> a/.hg/hgrc | |
|
120 | hg clone a zzz | |
|
121 | cd b | |
|
122 | 245 | |
|
123 | cat > hooktests.py <<EOF | |
|
124 | from mercurial import util | |
|
125 | ||
|
126 | uncallable = 0 | |
|
127 | ||
|
128 | def printargs(args): | |
|
129 | args.pop('ui', None) | |
|
130 | args.pop('repo', None) | |
|
131 | a = list(args.items()) | |
|
132 | a.sort() | |
|
133 | print 'hook args:' | |
|
134 | for k, v in a: | |
|
135 | print ' ', k, v | |
|
246 | $ echo 'preoutgoing.forbid = python ../printenv.py preoutgoing.forbid 1' >> a/.hg/hgrc | |
|
247 | $ hg clone a zzz | |
|
248 | preoutgoing hook: HG_SOURCE=clone | |
|
249 | preoutgoing.forbid hook: HG_SOURCE=clone | |
|
250 | abort: preoutgoing.forbid hook exited with status 1 | |
|
251 | $ cd b | |
|
136 | 252 | |
|
137 | def passhook(**args): | |
|
138 | printargs(args) | |
|
139 | ||
|
140 | def failhook(**args): | |
|
141 | printargs(args) | |
|
142 | return True | |
|
253 | $ cat > hooktests.py <<EOF | |
|
254 | > from mercurial import util | |
|
255 | > | |
|
256 | > uncallable = 0 | |
|
257 | > | |
|
258 | > def printargs(args): | |
|
259 | > args.pop('ui', None) | |
|
260 | > args.pop('repo', None) | |
|
261 | > a = list(args.items()) | |
|
262 | > a.sort() | |
|
263 | > print 'hook args:' | |
|
264 | > for k, v in a: | |
|
265 | > print ' ', k, v | |
|
266 | > | |
|
267 | > def passhook(**args): | |
|
268 | > printargs(args) | |
|
269 | > | |
|
270 | > def failhook(**args): | |
|
271 | > printargs(args) | |
|
272 | > return True | |
|
273 | > | |
|
274 | > class LocalException(Exception): | |
|
275 | > pass | |
|
276 | > | |
|
277 | > def raisehook(**args): | |
|
278 | > raise LocalException('exception from hook') | |
|
279 | > | |
|
280 | > def aborthook(**args): | |
|
281 | > raise util.Abort('raise abort from hook') | |
|
282 | > | |
|
283 | > def brokenhook(**args): | |
|
284 | > return 1 + {} | |
|
285 | > | |
|
286 | > class container: | |
|
287 | > unreachable = 1 | |
|
288 | > EOF | |
|
143 | 289 | |
|
144 | class LocalException(Exception): | |
|
145 | pass | |
|
146 | ||
|
147 | def raisehook(**args): | |
|
148 | raise LocalException('exception from hook') | |
|
290 | # test python hooks | |
|
149 | 291 | |
|
150 | def aborthook(**args): | |
|
151 | raise util.Abort('raise abort from hook') | |
|
152 | ||
|
153 | def brokenhook(**args): | |
|
154 | return 1 + {} | |
|
292 | $ PYTHONPATH="`pwd`:$PYTHONPATH" | |
|
293 | $ export PYTHONPATH | |
|
155 | 294 | |
|
156 | class container: | |
|
157 | unreachable = 1 | |
|
158 | EOF | |
|
295 | $ echo '[hooks]' > ../a/.hg/hgrc | |
|
296 | $ echo 'preoutgoing.broken = python:hooktests.brokenhook' >> ../a/.hg/hgrc | |
|
297 | $ hg pull ../a 2>&1 | grep 'raised an exception' | |
|
298 | error: preoutgoing.broken hook raised an exception: unsupported operand type(s) for +: 'int' and 'dict' | |
|
159 | 299 | |
|
160 | echo '# test python hooks' | |
|
161 | PYTHONPATH="`pwd`:$PYTHONPATH" | |
|
162 | export PYTHONPATH | |
|
300 | $ echo '[hooks]' > ../a/.hg/hgrc | |
|
301 | $ echo 'preoutgoing.raise = python:hooktests.raisehook' >> ../a/.hg/hgrc | |
|
302 | $ hg pull ../a 2>&1 | grep 'raised an exception' | |
|
303 | error: preoutgoing.raise hook raised an exception: exception from hook | |
|
163 | 304 | |
|
164 | echo '[hooks]' > ../a/.hg/hgrc | |
|
165 |
echo 'preoutgoing. |
|
|
166 | hg pull ../a 2>&1 | grep 'raised an exception' | |
|
305 | $ echo '[hooks]' > ../a/.hg/hgrc | |
|
306 | $ echo 'preoutgoing.abort = python:hooktests.aborthook' >> ../a/.hg/hgrc | |
|
307 | $ hg pull ../a | |
|
308 | pulling from ../a | |
|
309 | searching for changes | |
|
310 | error: preoutgoing.abort hook failed: raise abort from hook | |
|
311 | abort: raise abort from hook | |
|
167 | 312 | |
|
168 | echo '[hooks]' > ../a/.hg/hgrc | |
|
169 |
echo 'preoutgoing. |
|
|
170 | hg pull ../a 2>&1 | grep 'raised an exception' | |
|
171 | ||
|
172 | echo '[hooks]' > ../a/.hg/hgrc | |
|
173 | echo 'preoutgoing.abort = python:hooktests.aborthook' >> ../a/.hg/hgrc | |
|
174 | hg pull ../a | |
|
313 | $ echo '[hooks]' > ../a/.hg/hgrc | |
|
314 | $ echo 'preoutgoing.fail = python:hooktests.failhook' >> ../a/.hg/hgrc | |
|
315 | $ hg pull ../a | |
|
316 | pulling from ../a | |
|
317 | searching for changes | |
|
318 | hook args: | |
|
319 | hooktype preoutgoing | |
|
320 | source pull | |
|
321 | abort: preoutgoing.fail hook failed | |
|
175 | 322 | |
|
176 | echo '[hooks]' > ../a/.hg/hgrc | |
|
177 |
echo 'preoutgoing. |
|
|
178 | hg pull ../a | |
|
323 | $ echo '[hooks]' > ../a/.hg/hgrc | |
|
324 | $ echo 'preoutgoing.uncallable = python:hooktests.uncallable' >> ../a/.hg/hgrc | |
|
325 | $ hg pull ../a | |
|
326 | pulling from ../a | |
|
327 | searching for changes | |
|
328 | abort: preoutgoing.uncallable hook is invalid ("hooktests.uncallable" is not callable) | |
|
179 | 329 | |
|
180 | echo '[hooks]' > ../a/.hg/hgrc | |
|
181 |
echo 'preoutgoing. |
|
|
182 | hg pull ../a | |
|
330 | $ echo '[hooks]' > ../a/.hg/hgrc | |
|
331 | $ echo 'preoutgoing.nohook = python:hooktests.nohook' >> ../a/.hg/hgrc | |
|
332 | $ hg pull ../a | |
|
333 | pulling from ../a | |
|
334 | searching for changes | |
|
335 | abort: preoutgoing.nohook hook is invalid ("hooktests.nohook" is not defined) | |
|
183 | 336 | |
|
184 | echo '[hooks]' > ../a/.hg/hgrc | |
|
185 |
echo 'preoutgoing.no |
|
|
186 | hg pull ../a | |
|
337 | $ echo '[hooks]' > ../a/.hg/hgrc | |
|
338 | $ echo 'preoutgoing.nomodule = python:nomodule' >> ../a/.hg/hgrc | |
|
339 | $ hg pull ../a | |
|
340 | pulling from ../a | |
|
341 | searching for changes | |
|
342 | abort: preoutgoing.nomodule hook is invalid ("nomodule" not in a module) | |
|
187 | 343 | |
|
188 | echo '[hooks]' > ../a/.hg/hgrc | |
|
189 |
echo 'preoutgoing. |
|
|
190 | hg pull ../a | |
|
191 | ||
|
192 | echo '[hooks]' > ../a/.hg/hgrc | |
|
193 | echo 'preoutgoing.badmodule = python:nomodule.nowhere' >> ../a/.hg/hgrc | |
|
194 | hg pull ../a | |
|
344 | $ echo '[hooks]' > ../a/.hg/hgrc | |
|
345 | $ echo 'preoutgoing.badmodule = python:nomodule.nowhere' >> ../a/.hg/hgrc | |
|
346 | $ hg pull ../a | |
|
347 | pulling from ../a | |
|
348 | searching for changes | |
|
349 | abort: preoutgoing.badmodule hook is invalid (import of "nomodule" failed) | |
|
195 | 350 | |
|
196 | echo '[hooks]' > ../a/.hg/hgrc | |
|
197 | echo 'preoutgoing.unreachable = python:hooktests.container.unreachable' >> ../a/.hg/hgrc | |
|
198 | hg pull ../a | |
|
351 | $ echo '[hooks]' > ../a/.hg/hgrc | |
|
352 | $ echo 'preoutgoing.unreachable = python:hooktests.container.unreachable' >> ../a/.hg/hgrc | |
|
353 | $ hg pull ../a | |
|
354 | pulling from ../a | |
|
355 | searching for changes | |
|
356 | abort: preoutgoing.unreachable hook is invalid (import of "hooktests.container" failed) | |
|
199 | 357 | |
|
200 | echo '[hooks]' > ../a/.hg/hgrc | |
|
201 | echo 'preoutgoing.pass = python:hooktests.passhook' >> ../a/.hg/hgrc | |
|
202 | hg pull ../a | |
|
358 | $ echo '[hooks]' > ../a/.hg/hgrc | |
|
359 | $ echo 'preoutgoing.pass = python:hooktests.passhook' >> ../a/.hg/hgrc | |
|
360 | $ hg pull ../a | |
|
361 | pulling from ../a | |
|
362 | searching for changes | |
|
363 | hook args: | |
|
364 | hooktype preoutgoing | |
|
365 | source pull | |
|
366 | adding changesets | |
|
367 | adding manifests | |
|
368 | adding file changes | |
|
369 | added 1 changesets with 1 changes to 1 files | |
|
370 | (run 'hg update' to get a working copy) | |
|
203 | 371 | |
|
204 |
|
|
|
205 | echo '[hooks]' > .hg/hgrc | |
|
206 | echo 'commit.abort = python:hooktests.aborthook' >> .hg/hgrc | |
|
372 | # make sure --traceback works | |
|
207 | 373 | |
|
208 | echo aa > a | |
|
209 | hg --traceback commit -d '0 0' -ma 2>&1 | grep '^Traceback' | |
|
374 | $ echo '[hooks]' > .hg/hgrc | |
|
375 | $ echo 'commit.abort = python:hooktests.aborthook' >> .hg/hgrc | |
|
210 | 376 | |
|
211 | cd .. | |
|
212 | hg init c | |
|
213 | cd c | |
|
377 | $ echo aa > a | |
|
378 | $ hg --traceback commit -d '0 0' -ma 2>&1 | grep '^Traceback' | |
|
379 | Traceback (most recent call last): | |
|
214 | 380 | |
|
215 | cat > hookext.py <<EOF | |
|
216 | def autohook(**args): | |
|
217 | print "Automatically installed hook" | |
|
381 | $ cd .. | |
|
382 | $ hg init c | |
|
383 | $ cd c | |
|
218 | 384 | |
|
219 | def reposetup(ui, repo): | |
|
220 | repo.ui.setconfig("hooks", "commit.auto", autohook) | |
|
221 | EOF | |
|
222 | echo '[extensions]' >> .hg/hgrc | |
|
223 | echo 'hookext = hookext.py' >> .hg/hgrc | |
|
385 | $ cat > hookext.py <<EOF | |
|
386 | > def autohook(**args): | |
|
387 | > print "Automatically installed hook" | |
|
388 | > | |
|
389 | > def reposetup(ui, repo): | |
|
390 | > repo.ui.setconfig("hooks", "commit.auto", autohook) | |
|
391 | > EOF | |
|
392 | $ echo '[extensions]' >> .hg/hgrc | |
|
393 | $ echo 'hookext = hookext.py' >> .hg/hgrc | |
|
224 | 394 | |
|
225 | touch foo | |
|
226 | hg add foo | |
|
227 | hg ci -d '0 0' -m 'add foo' | |
|
228 | echo >> foo | |
|
229 | hg ci --debug -d '0 0' -m 'change foo' | sed -e 's/ at .*>/>/' | |
|
395 | $ touch foo | |
|
396 | $ hg add foo | |
|
397 | $ hg ci -d '0 0' -m 'add foo' | |
|
398 | Automatically installed hook | |
|
399 | $ echo >> foo | |
|
400 | $ hg ci --debug -d '0 0' -m 'change foo' | sed -e 's/ at .*>/>/' | |
|
401 | foo | |
|
402 | calling hook commit.auto: <function autohook> | |
|
403 | Automatically installed hook | |
|
404 | committed changeset 1:52998019f6252a2b893452765fcb0a47351a5708 | |
|
230 | 405 | |
|
231 | hg showconfig hooks | sed -e 's/ at .*>/>/' | |
|
406 | $ hg showconfig hooks | sed -e 's/ at .*>/>/' | |
|
407 | hooks.commit.auto=<function autohook> | |
|
232 | 408 | |
|
233 |
|
|
|
234 | cd .. | |
|
235 | mkdir d | |
|
236 | cd d | |
|
237 | hg init repo | |
|
238 | mkdir hooks | |
|
409 | # test python hook configured with python:[file]:[hook] syntax | |
|
410 | ||
|
411 | $ cd .. | |
|
412 | $ mkdir d | |
|
413 | $ cd d | |
|
414 | $ hg init repo | |
|
415 | $ mkdir hooks | |
|
239 | 416 | |
|
240 | cd hooks | |
|
241 | cat > testhooks.py <<EOF | |
|
242 | def testhook(**args): | |
|
243 | print 'hook works' | |
|
244 | EOF | |
|
245 | echo '[hooks]' > ../repo/.hg/hgrc | |
|
246 | echo "pre-commit.test = python:`pwd`/testhooks.py:testhook" >> ../repo/.hg/hgrc | |
|
417 | $ cd hooks | |
|
418 | $ cat > testhooks.py <<EOF | |
|
419 | > def testhook(**args): | |
|
420 | > print 'hook works' | |
|
421 | > EOF | |
|
422 | $ echo '[hooks]' > ../repo/.hg/hgrc | |
|
423 | $ echo "pre-commit.test = python:`pwd`/testhooks.py:testhook" >> ../repo/.hg/hgrc | |
|
247 | 424 | |
|
248 | cd ../repo | |
|
249 | hg commit -d '0 0' | |
|
425 | $ cd ../repo | |
|
426 | $ hg commit -d '0 0' | |
|
427 | hook works | |
|
428 | nothing changed | |
|
429 | ||
|
430 | $ cd ../../b | |
|
431 | ||
|
432 | # make sure --traceback works on hook import failure | |
|
250 | 433 | |
|
251 | cd ../../b | |
|
252 | echo '# make sure --traceback works on hook import failure' | |
|
253 | cat > importfail.py <<EOF | |
|
254 |
|
|
|
255 | # dereference something in the module to force demandimport to load it | |
|
256 | somebogusmodule.whatever | |
|
257 | EOF | |
|
434 | $ cat > importfail.py <<EOF | |
|
435 | > import somebogusmodule | |
|
436 | > # dereference something in the module to force demandimport to load it | |
|
437 | > somebogusmodule.whatever | |
|
438 | > EOF | |
|
258 | 439 | |
|
259 | echo '[hooks]' > .hg/hgrc | |
|
260 | echo 'precommit.importfail = python:importfail.whatever' >> .hg/hgrc | |
|
440 | $ echo '[hooks]' > .hg/hgrc | |
|
441 | $ echo 'precommit.importfail = python:importfail.whatever' >> .hg/hgrc | |
|
261 | 442 | |
|
262 | echo a >> a | |
|
263 | hg --traceback commit -d '0 0' -ma 2>&1 | egrep '^(exception|Traceback|ImportError)' | |
|
443 | $ echo a >> a | |
|
444 | $ hg --traceback commit -d '0 0' -ma 2>&1 | egrep '^(exception|Traceback|ImportError)' | |
|
445 | exception from first failed import attempt: | |
|
446 | Traceback (most recent call last): | |
|
447 | ImportError: No module named somebogusmodule | |
|
448 | exception from second failed import attempt: | |
|
449 | Traceback (most recent call last): | |
|
450 | ImportError: No module named hgext_importfail | |
|
451 | Traceback (most recent call last): | |
|
452 | ||
|
453 | # commit and update hooks should run after command completion (issue 1827) | |
|
264 | 454 | |
|
265 | echo '# commit and update hooks should run after command completion (issue 1827)' | |
|
266 |
echo ' |
|
|
267 |
echo ' |
|
|
268 | echo 'update = hg id' >> .hg/hgrc | |
|
269 | echo bb > a | |
|
270 | hg ci -d '0 0' -ma | |
|
271 | hg up 0 | |
|
455 | $ echo '[hooks]' > .hg/hgrc | |
|
456 | $ echo 'commit = hg id' >> .hg/hgrc | |
|
457 | $ echo 'update = hg id' >> .hg/hgrc | |
|
458 | $ echo bb > a | |
|
459 | $ hg ci -d '0 0' -ma | |
|
460 | 8da618c33484 tip | |
|
461 | $ hg up 0 | |
|
462 | 29b62aeb769f | |
|
463 | 1 files updated, 0 files merged, 0 files removed, 0 files unresolved | |
|
272 | 464 | |
|
273 | exit 0 | |
|
465 | $ exit 0 |
|
1 | NO CONTENT: file was removed |
General Comments 0
You need to be logged in to leave comments.
Login now