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 |
|
1 | $ cp "$TESTDIR"/printenv.py . | |
2 |
|
||||
3 | cp "$TESTDIR"/printenv.py . |
|
|||
4 |
|
2 | |||
5 | # commit hooks can see env vars |
|
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 |
|
5 | $ hg init a | |
22 | cd ../b |
|
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 | # changegroup hooks can see env vars |
|
30 | # changegroup hooks can see env vars | |
25 | echo '[hooks]' > .hg/hgrc |
|
31 | ||
26 | echo 'prechangegroup = python ../printenv.py prechangegroup' >> .hg/hgrc |
|
32 | $ echo '[hooks]' > .hg/hgrc | |
27 | echo 'changegroup = python ../printenv.py changegroup' >> .hg/hgrc |
|
33 | $ echo 'prechangegroup = python ../printenv.py prechangegroup' >> .hg/hgrc | |
28 |
echo ' |
|
34 | $ echo 'changegroup = python ../printenv.py changegroup' >> .hg/hgrc | |
|
35 | $ echo 'incoming = python ../printenv.py incoming' >> .hg/hgrc | |||
29 |
|
36 | |||
30 | # pretxncommit and commit hooks can see both parents of merge |
|
37 | # pretxncommit and commit hooks can see both parents of merge | |
31 | cd ../a |
|
38 | ||
32 | echo b >> a |
|
39 | $ cd ../a | |
33 | hg commit -m a1 -d "1 0" |
|
40 | $ echo b >> a | |
34 | hg update -C 0 |
|
41 | $ hg commit -m a1 -d "1 0" | |
35 | echo b > b |
|
42 | precommit hook: HG_PARENT1=29b62aeb769fdf78d8d9c5f28b017f76d7ef824b | |
36 | hg add b |
|
43 | pretxncommit hook: HG_NODE=b702efe9688826e3a91283852b328b84dbf37bc2 HG_PARENT1=29b62aeb769fdf78d8d9c5f28b017f76d7ef824b HG_PENDING=$HGTMP/test-hook.t/a | |
37 | hg commit -m b -d '1 0' |
|
44 | 1:b702efe96888 | |
38 | hg merge 1 |
|
45 | commit hook: HG_NODE=b702efe9688826e3a91283852b328b84dbf37bc2 HG_PARENT1=29b62aeb769fdf78d8d9c5f28b017f76d7ef824b | |
39 | hg commit -m merge -d '2 0' |
|
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 | # test generic hooks |
|
68 | # test generic hooks | |
42 | hg id |
|
69 | ||
43 | hg cat b |
|
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 |
|
78 | $ cd ../b | |
46 | hg pull ../a |
|
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 | # tag hooks can see env vars |
|
93 | # tag hooks can see env vars | |
49 | cd ../a |
|
94 | ||
50 | echo 'pretag = python ../printenv.py pretag' >> .hg/hgrc |
|
95 | $ cd ../a | |
51 |
echo 'tag = |
|
96 | $ echo 'pretag = python ../printenv.py pretag' >> .hg/hgrc | |
52 | hg tag -d '3 0' a |
|
97 | $ echo 'tag = unset HG_PARENT1 HG_PARENT2; python ../printenv.py tag' >> .hg/hgrc | |
53 |
hg tag - |
|
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 | # pretag hook can forbid tagging |
|
110 | # pretag hook can forbid tagging | |
56 | echo 'pretag.forbid = python ../printenv.py pretag.forbid 1' >> .hg/hgrc |
|
111 | ||
57 | hg tag -d '4 0' fa |
|
112 | $ echo 'pretag.forbid = python ../printenv.py pretag.forbid 1' >> .hg/hgrc | |
58 |
hg tag - |
|
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 | # pretxncommit hook can see changeset, can roll back txn, changeset |
|
122 | # pretxncommit hook can see changeset, can roll back txn, changeset | |
61 | # no more there after |
|
123 | # no more there after | |
62 | echo 'pretxncommit.forbid0 = hg tip -q' >> .hg/hgrc |
|
124 | ||
63 |
echo 'pretxncommit.forbid |
|
125 | $ echo 'pretxncommit.forbid0 = hg tip -q' >> .hg/hgrc | |
64 | echo z > z |
|
126 | $ echo 'pretxncommit.forbid1 = python ../printenv.py pretxncommit.forbid 1' >> .hg/hgrc | |
65 | hg add z |
|
127 | $ echo z > z | |
66 | hg -q tip |
|
128 | $ hg add z | |
67 | hg commit -m 'fail' -d '4 0' |
|
129 | $ hg -q tip | |
68 | 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 | # precommit hook can prevent commit |
|
143 | # precommit hook can prevent commit | |
71 | echo 'precommit.forbid = python ../printenv.py precommit.forbid 1' >> .hg/hgrc |
|
144 | ||
72 | hg commit -m 'fail' -d '4 0' |
|
145 | $ echo 'precommit.forbid = python ../printenv.py precommit.forbid 1' >> .hg/hgrc | |
73 | hg -q tip |
|
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 | # preupdate hook can prevent update |
|
153 | # preupdate hook can prevent update | |
76 | echo 'preupdate = python ../printenv.py preupdate' >> .hg/hgrc |
|
154 | ||
77 | hg update 1 |
|
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 | # update hook |
|
160 | # update hook | |
80 | echo 'update = python ../printenv.py update' >> .hg/hgrc |
|
161 | ||
81 | hg update |
|
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 | # prechangegroup hook can prevent incoming changes |
|
168 | # prechangegroup hook can prevent incoming changes | |
84 | cd ../b |
|
169 | ||
85 | hg -q tip |
|
170 | $ cd ../b | |
86 | echo '[hooks]' > .hg/hgrc |
|
171 | $ hg -q tip | |
87 | echo 'prechangegroup.forbid = python ../printenv.py prechangegroup.forbid 1' >> .hg/hgrc |
|
172 | 3:4c52fb2e4022 | |
88 | hg pull ../a |
|
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 | # pretxnchangegroup hook can see incoming changes, can roll back txn, |
|
181 | # pretxnchangegroup hook can see incoming changes, can roll back txn, | |
91 | # incoming changes no longer there after |
|
182 | # incoming changes no longer there after | |
92 | echo '[hooks]' > .hg/hgrc |
|
183 | ||
93 | echo 'pretxnchangegroup.forbid0 = hg tip -q' >> .hg/hgrc |
|
184 | $ echo '[hooks]' > .hg/hgrc | |
94 |
echo 'pretxnchangegroup.forbid |
|
185 | $ echo 'pretxnchangegroup.forbid0 = hg tip -q' >> .hg/hgrc | |
95 | hg pull ../a |
|
186 | $ echo 'pretxnchangegroup.forbid1 = python ../printenv.py pretxnchangegroup.forbid 1' >> .hg/hgrc | |
96 | hg -q tip |
|
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 | # outgoing hooks can see env vars |
|
202 | # outgoing hooks can see env vars | |
99 | rm .hg/hgrc |
|
203 | ||
100 | echo '[hooks]' > ../a/.hg/hgrc |
|
204 | $ rm .hg/hgrc | |
101 | echo 'preoutgoing = python ../printenv.py preoutgoing' >> ../a/.hg/hgrc |
|
205 | $ echo '[hooks]' > ../a/.hg/hgrc | |
102 | echo 'outgoing = python ../printenv.py outgoing' >> ../a/.hg/hgrc |
|
206 | $ echo 'preoutgoing = python ../printenv.py preoutgoing' >> ../a/.hg/hgrc | |
103 | hg pull ../a |
|
207 | $ echo 'outgoing = python ../printenv.py outgoing' >> ../a/.hg/hgrc | |
104 | hg rollback |
|
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 | # preoutgoing hook can prevent outgoing changes |
|
221 | # preoutgoing hook can prevent outgoing changes | |
107 | echo 'preoutgoing.forbid = python ../printenv.py preoutgoing.forbid 1' >> ../a/.hg/hgrc |
|
222 | ||
108 | hg pull ../a |
|
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 | # outgoing hooks work for local clones |
|
231 | # outgoing hooks work for local clones | |
111 | cd .. |
|
232 | ||
112 | echo '[hooks]' > a/.hg/hgrc |
|
233 | $ cd .. | |
113 | echo 'preoutgoing = python ../printenv.py preoutgoing' >> a/.hg/hgrc |
|
234 | $ echo '[hooks]' > a/.hg/hgrc | |
114 | echo 'outgoing = python ../printenv.py outgoing' >> a/.hg/hgrc |
|
235 | $ echo 'preoutgoing = python ../printenv.py preoutgoing' >> a/.hg/hgrc | |
115 | hg clone a c |
|
236 | $ echo 'outgoing = python ../printenv.py outgoing' >> a/.hg/hgrc | |
116 | rm -rf c |
|
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 | # preoutgoing hook can prevent outgoing changes for local clones |
|
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 |
|
246 | $ echo 'preoutgoing.forbid = python ../printenv.py preoutgoing.forbid 1' >> a/.hg/hgrc | |
124 | from mercurial import util |
|
247 | $ hg clone a zzz | |
125 |
|
248 | preoutgoing hook: HG_SOURCE=clone | ||
126 | uncallable = 0 |
|
249 | preoutgoing.forbid hook: HG_SOURCE=clone | |
127 |
|
250 | abort: preoutgoing.forbid hook exited with status 1 | ||
128 | def printargs(args): |
|
251 | $ cd b | |
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 |
|
|||
136 |
|
252 | |||
137 | def passhook(**args): |
|
253 | $ cat > hooktests.py <<EOF | |
138 | printargs(args) |
|
254 | > from mercurial import util | |
139 |
|
255 | > | ||
140 | def failhook(**args): |
|
256 | > uncallable = 0 | |
141 | printargs(args) |
|
257 | > | |
142 | return True |
|
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): |
|
290 | # test python hooks | |
145 | pass |
|
|||
146 |
|
||||
147 | def raisehook(**args): |
|
|||
148 | raise LocalException('exception from hook') |
|
|||
149 |
|
291 | |||
150 | def aborthook(**args): |
|
292 | $ PYTHONPATH="`pwd`:$PYTHONPATH" | |
151 | raise util.Abort('raise abort from hook') |
|
293 | $ export PYTHONPATH | |
152 |
|
||||
153 | def brokenhook(**args): |
|
|||
154 | return 1 + {} |
|
|||
155 |
|
294 | |||
156 | class container: |
|
295 | $ echo '[hooks]' > ../a/.hg/hgrc | |
157 | unreachable = 1 |
|
296 | $ echo 'preoutgoing.broken = python:hooktests.brokenhook' >> ../a/.hg/hgrc | |
158 | EOF |
|
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' |
|
300 | $ echo '[hooks]' > ../a/.hg/hgrc | |
161 | PYTHONPATH="`pwd`:$PYTHONPATH" |
|
301 | $ echo 'preoutgoing.raise = python:hooktests.raisehook' >> ../a/.hg/hgrc | |
162 | export PYTHONPATH |
|
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 |
|
305 | $ echo '[hooks]' > ../a/.hg/hgrc | |
165 |
echo 'preoutgoing. |
|
306 | $ echo 'preoutgoing.abort = python:hooktests.aborthook' >> ../a/.hg/hgrc | |
166 | hg pull ../a 2>&1 | grep 'raised an exception' |
|
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 |
|
313 | $ echo '[hooks]' > ../a/.hg/hgrc | |
169 |
echo 'preoutgoing. |
|
314 | $ echo 'preoutgoing.fail = python:hooktests.failhook' >> ../a/.hg/hgrc | |
170 | hg pull ../a 2>&1 | grep 'raised an exception' |
|
315 | $ hg pull ../a | |
171 |
|
316 | pulling from ../a | ||
172 | echo '[hooks]' > ../a/.hg/hgrc |
|
317 | searching for changes | |
173 | echo 'preoutgoing.abort = python:hooktests.aborthook' >> ../a/.hg/hgrc |
|
318 | hook args: | |
174 | hg pull ../a |
|
319 | hooktype preoutgoing | |
|
320 | source pull | |||
|
321 | abort: preoutgoing.fail hook failed | |||
175 |
|
322 | |||
176 | echo '[hooks]' > ../a/.hg/hgrc |
|
323 | $ echo '[hooks]' > ../a/.hg/hgrc | |
177 |
echo 'preoutgoing. |
|
324 | $ echo 'preoutgoing.uncallable = python:hooktests.uncallable' >> ../a/.hg/hgrc | |
178 | hg pull ../a |
|
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 |
|
330 | $ echo '[hooks]' > ../a/.hg/hgrc | |
181 |
echo 'preoutgoing. |
|
331 | $ echo 'preoutgoing.nohook = python:hooktests.nohook' >> ../a/.hg/hgrc | |
182 | hg pull ../a |
|
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 |
|
337 | $ echo '[hooks]' > ../a/.hg/hgrc | |
185 |
echo 'preoutgoing.no |
|
338 | $ echo 'preoutgoing.nomodule = python:nomodule' >> ../a/.hg/hgrc | |
186 | hg pull ../a |
|
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 |
|
344 | $ echo '[hooks]' > ../a/.hg/hgrc | |
189 |
echo 'preoutgoing. |
|
345 | $ echo 'preoutgoing.badmodule = python:nomodule.nowhere' >> ../a/.hg/hgrc | |
190 | hg pull ../a |
|
346 | $ hg pull ../a | |
191 |
|
347 | pulling from ../a | ||
192 | echo '[hooks]' > ../a/.hg/hgrc |
|
348 | searching for changes | |
193 | echo 'preoutgoing.badmodule = python:nomodule.nowhere' >> ../a/.hg/hgrc |
|
349 | abort: preoutgoing.badmodule hook is invalid (import of "nomodule" failed) | |
194 | hg pull ../a |
|
|||
195 |
|
350 | |||
196 | echo '[hooks]' > ../a/.hg/hgrc |
|
351 | $ echo '[hooks]' > ../a/.hg/hgrc | |
197 | echo 'preoutgoing.unreachable = python:hooktests.container.unreachable' >> ../a/.hg/hgrc |
|
352 | $ echo 'preoutgoing.unreachable = python:hooktests.container.unreachable' >> ../a/.hg/hgrc | |
198 | hg pull ../a |
|
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 |
|
358 | $ echo '[hooks]' > ../a/.hg/hgrc | |
201 | echo 'preoutgoing.pass = python:hooktests.passhook' >> ../a/.hg/hgrc |
|
359 | $ echo 'preoutgoing.pass = python:hooktests.passhook' >> ../a/.hg/hgrc | |
202 | hg pull ../a |
|
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 |
|
|
372 | # make sure --traceback works | |
205 | echo '[hooks]' > .hg/hgrc |
|
|||
206 | echo 'commit.abort = python:hooktests.aborthook' >> .hg/hgrc |
|
|||
207 |
|
373 | |||
208 | echo aa > a |
|
374 | $ echo '[hooks]' > .hg/hgrc | |
209 | hg --traceback commit -d '0 0' -ma 2>&1 | grep '^Traceback' |
|
375 | $ echo 'commit.abort = python:hooktests.aborthook' >> .hg/hgrc | |
210 |
|
376 | |||
211 | cd .. |
|
377 | $ echo aa > a | |
212 | hg init c |
|
378 | $ hg --traceback commit -d '0 0' -ma 2>&1 | grep '^Traceback' | |
213 | cd c |
|
379 | Traceback (most recent call last): | |
214 |
|
380 | |||
215 | cat > hookext.py <<EOF |
|
381 | $ cd .. | |
216 | def autohook(**args): |
|
382 | $ hg init c | |
217 | print "Automatically installed hook" |
|
383 | $ cd c | |
218 |
|
384 | |||
219 | def reposetup(ui, repo): |
|
385 | $ cat > hookext.py <<EOF | |
220 | repo.ui.setconfig("hooks", "commit.auto", autohook) |
|
386 | > def autohook(**args): | |
221 | EOF |
|
387 | > print "Automatically installed hook" | |
222 | echo '[extensions]' >> .hg/hgrc |
|
388 | > | |
223 | echo 'hookext = hookext.py' >> .hg/hgrc |
|
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 |
|
395 | $ touch foo | |
226 | hg add foo |
|
396 | $ hg add foo | |
227 | hg ci -d '0 0' -m 'add foo' |
|
397 | $ hg ci -d '0 0' -m 'add foo' | |
228 | echo >> foo |
|
398 | Automatically installed hook | |
229 | hg ci --debug -d '0 0' -m 'change foo' | sed -e 's/ at .*>/>/' |
|
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 |
|
|
409 | # test python hook configured with python:[file]:[hook] syntax | |
234 | cd .. |
|
410 | ||
235 | mkdir d |
|
411 | $ cd .. | |
236 | cd d |
|
412 | $ mkdir d | |
237 | hg init repo |
|
413 | $ cd d | |
238 | mkdir hooks |
|
414 | $ hg init repo | |
|
415 | $ mkdir hooks | |||
239 |
|
416 | |||
240 | cd hooks |
|
417 | $ cd hooks | |
241 | cat > testhooks.py <<EOF |
|
418 | $ cat > testhooks.py <<EOF | |
242 | def testhook(**args): |
|
419 | > def testhook(**args): | |
243 | print 'hook works' |
|
420 | > print 'hook works' | |
244 | EOF |
|
421 | > EOF | |
245 | echo '[hooks]' > ../repo/.hg/hgrc |
|
422 | $ echo '[hooks]' > ../repo/.hg/hgrc | |
246 | echo "pre-commit.test = python:`pwd`/testhooks.py:testhook" >> ../repo/.hg/hgrc |
|
423 | $ echo "pre-commit.test = python:`pwd`/testhooks.py:testhook" >> ../repo/.hg/hgrc | |
247 |
|
424 | |||
248 | cd ../repo |
|
425 | $ cd ../repo | |
249 | hg commit -d '0 0' |
|
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 |
|
434 | $ cat > importfail.py <<EOF | |
252 | echo '# make sure --traceback works on hook import failure' |
|
435 | > import somebogusmodule | |
253 | cat > importfail.py <<EOF |
|
436 | > # dereference something in the module to force demandimport to load it | |
254 |
|
|
437 | > somebogusmodule.whatever | |
255 | # dereference something in the module to force demandimport to load it |
|
438 | > EOF | |
256 | somebogusmodule.whatever |
|
|||
257 | EOF |
|
|||
258 |
|
439 | |||
259 | echo '[hooks]' > .hg/hgrc |
|
440 | $ echo '[hooks]' > .hg/hgrc | |
260 | echo 'precommit.importfail = python:importfail.whatever' >> .hg/hgrc |
|
441 | $ echo 'precommit.importfail = python:importfail.whatever' >> .hg/hgrc | |
261 |
|
442 | |||
262 | echo a >> a |
|
443 | $ echo a >> a | |
263 | hg --traceback commit -d '0 0' -ma 2>&1 | egrep '^(exception|Traceback|ImportError)' |
|
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)' |
|
455 | $ echo '[hooks]' > .hg/hgrc | |
266 |
echo ' |
|
456 | $ echo 'commit = hg id' >> .hg/hgrc | |
267 |
echo ' |
|
457 | $ echo 'update = hg id' >> .hg/hgrc | |
268 | echo 'update = hg id' >> .hg/hgrc |
|
458 | $ echo bb > a | |
269 | echo bb > a |
|
459 | $ hg ci -d '0 0' -ma | |
270 | hg ci -d '0 0' -ma |
|
460 | 8da618c33484 tip | |
271 | hg up 0 |
|
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 |
|
NO CONTENT: file was removed |
General Comments 0
You need to be logged in to leave comments.
Login now