Mercurial > hg
annotate tests/test-hook @ 4531:b51a8138292a
Avoid extra filelogs entries.
Right now, there are some situations in which localrepo.filecommit can
create filelog entries even though they're not needed. For example:
- permissions for a file have changed;
- qrefresh can create a filelog entry identical to its parent (see the
added test);
- convert-repo creates extra filelog entries in every merge where the
first parent has added files (for example, changeset ebebe9577a1a of
the kernel repo added extra filelog entries to files in the
arch/blackfin directory, even though the merge should only touch the
drivers/ata directory). This makes "hg log file" in a converted repo
less useful than it could be, since it may mention many merges that
don't actually touch that specific file.
They all come from the same basic problem: localrepo.commit (through
filecommit) creates new filelog entries for all files passed to it
(except for some cases during a merge).
Patch and test case provided by Benoit.
This should fix issue351.
author | Alexis S. L. Carvalho <alexis@cecm.usp.br> |
---|---|
date | Sat, 09 Jun 2007 01:04:28 -0300 |
parents | 97962a3e73cf |
children | e6d105a51ec7 |
rev | line source |
---|---|
800
ec85f9e6f3b1
Don't use 'set -x', fix exports, sed and hexdump usage for Solaris.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
749
diff
changeset
|
1 #!/bin/sh |
487 | 2 |
4286
949516072388
test-hook: use printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4085
diff
changeset
|
3 cp "$TESTDIR"/printenv.py . |
949516072388
test-hook: use printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4085
diff
changeset
|
4 |
1734
9488d53233b5
tests for new hooks. fix things i found when writing tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1481
diff
changeset
|
5 # commit hooks can see env vars |
9488d53233b5
tests for new hooks. fix things i found when writing tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1481
diff
changeset
|
6 hg init a |
9488d53233b5
tests for new hooks. fix things i found when writing tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1481
diff
changeset
|
7 cd a |
487 | 8 echo "[hooks]" > .hg/hgrc |
4368
97962a3e73cf
Work around problem where 'del os.environ["FOO"]' doesn't update environment.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4286
diff
changeset
|
9 echo 'commit = unset HG_LOCAL HG_TAG; python ../printenv.py commit' >> .hg/hgrc |
97962a3e73cf
Work around problem where 'del os.environ["FOO"]' doesn't update environment.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4286
diff
changeset
|
10 echo 'commit.b = unset HG_LOCAL HG_TAG; python ../printenv.py commit.b' >> .hg/hgrc |
97962a3e73cf
Work around problem where 'del os.environ["FOO"]' doesn't update environment.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4286
diff
changeset
|
11 echo 'precommit = unset HG_LOCAL HG_NODE HG_TAG; python ../printenv.py precommit' >> .hg/hgrc |
97962a3e73cf
Work around problem where 'del os.environ["FOO"]' doesn't update environment.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4286
diff
changeset
|
12 echo 'pretxncommit = unset HG_LOCAL HG_TAG; python ../printenv.py pretxncommit' >> .hg/hgrc |
4286
949516072388
test-hook: use printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4085
diff
changeset
|
13 echo 'pretxncommit.tip = hg -q tip' >> .hg/hgrc |
487 | 14 echo a > a |
15 hg add a | |
1933
7544700fd931
Use 'hg ci -d "1000000 0"' in tests to circumvent problem with leading zero.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1736
diff
changeset
|
16 hg commit -m a -d "1000000 0" |
1734
9488d53233b5
tests for new hooks. fix things i found when writing tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1481
diff
changeset
|
17 |
9488d53233b5
tests for new hooks. fix things i found when writing tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1481
diff
changeset
|
18 hg clone . ../b |
9488d53233b5
tests for new hooks. fix things i found when writing tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1481
diff
changeset
|
19 cd ../b |
9488d53233b5
tests for new hooks. fix things i found when writing tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1481
diff
changeset
|
20 |
9488d53233b5
tests for new hooks. fix things i found when writing tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1481
diff
changeset
|
21 # changegroup hooks can see env vars |
9488d53233b5
tests for new hooks. fix things i found when writing tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1481
diff
changeset
|
22 echo '[hooks]' > .hg/hgrc |
4286
949516072388
test-hook: use printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4085
diff
changeset
|
23 echo 'prechangegroup = python ../printenv.py prechangegroup' >> .hg/hgrc |
949516072388
test-hook: use printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4085
diff
changeset
|
24 echo 'changegroup = python ../printenv.py changegroup' >> .hg/hgrc |
949516072388
test-hook: use printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4085
diff
changeset
|
25 echo 'incoming = python ../printenv.py incoming' >> .hg/hgrc |
1734
9488d53233b5
tests for new hooks. fix things i found when writing tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1481
diff
changeset
|
26 |
9488d53233b5
tests for new hooks. fix things i found when writing tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1481
diff
changeset
|
27 # pretxncommit and commit hooks can see both parents of merge |
9488d53233b5
tests for new hooks. fix things i found when writing tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1481
diff
changeset
|
28 cd ../a |
9488d53233b5
tests for new hooks. fix things i found when writing tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1481
diff
changeset
|
29 echo b >> a |
9488d53233b5
tests for new hooks. fix things i found when writing tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1481
diff
changeset
|
30 hg commit -m a1 -d "1 0" |
9488d53233b5
tests for new hooks. fix things i found when writing tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1481
diff
changeset
|
31 hg update -C 0 |
9488d53233b5
tests for new hooks. fix things i found when writing tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1481
diff
changeset
|
32 echo b > b |
9488d53233b5
tests for new hooks. fix things i found when writing tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1481
diff
changeset
|
33 hg add b |
9488d53233b5
tests for new hooks. fix things i found when writing tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1481
diff
changeset
|
34 hg commit -m b -d '1 0' |
2283
e506c14382fd
deprecate 'update -m'. use 'merge' instead.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2266
diff
changeset
|
35 hg merge 1 |
1734
9488d53233b5
tests for new hooks. fix things i found when writing tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1481
diff
changeset
|
36 hg commit -m merge -d '2 0' |
9488d53233b5
tests for new hooks. fix things i found when writing tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1481
diff
changeset
|
37 |
9488d53233b5
tests for new hooks. fix things i found when writing tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1481
diff
changeset
|
38 cd ../b |
9488d53233b5
tests for new hooks. fix things i found when writing tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1481
diff
changeset
|
39 hg pull ../a |
9488d53233b5
tests for new hooks. fix things i found when writing tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1481
diff
changeset
|
40 |
9488d53233b5
tests for new hooks. fix things i found when writing tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1481
diff
changeset
|
41 # tag hooks can see env vars |
9488d53233b5
tests for new hooks. fix things i found when writing tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1481
diff
changeset
|
42 cd ../a |
4286
949516072388
test-hook: use printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4085
diff
changeset
|
43 echo 'pretag = python ../printenv.py pretag' >> .hg/hgrc |
4368
97962a3e73cf
Work around problem where 'del os.environ["FOO"]' doesn't update environment.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4286
diff
changeset
|
44 echo 'tag = unset HG_PARENT1 HG_PARENT2; python ../printenv.py tag' >> .hg/hgrc |
1734
9488d53233b5
tests for new hooks. fix things i found when writing tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1481
diff
changeset
|
45 hg tag -d '3 0' a |
9488d53233b5
tests for new hooks. fix things i found when writing tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1481
diff
changeset
|
46 hg tag -l la |
9488d53233b5
tests for new hooks. fix things i found when writing tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1481
diff
changeset
|
47 |
9488d53233b5
tests for new hooks. fix things i found when writing tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1481
diff
changeset
|
48 # pretag hook can forbid tagging |
4286
949516072388
test-hook: use printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4085
diff
changeset
|
49 echo 'pretag.forbid = python ../printenv.py pretag.forbid 1' >> .hg/hgrc |
1734
9488d53233b5
tests for new hooks. fix things i found when writing tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1481
diff
changeset
|
50 hg tag -d '4 0' fa |
9488d53233b5
tests for new hooks. fix things i found when writing tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1481
diff
changeset
|
51 hg tag -l fla |
9488d53233b5
tests for new hooks. fix things i found when writing tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1481
diff
changeset
|
52 |
9488d53233b5
tests for new hooks. fix things i found when writing tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1481
diff
changeset
|
53 # pretxncommit hook can see changeset, can roll back txn, changeset |
9488d53233b5
tests for new hooks. fix things i found when writing tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1481
diff
changeset
|
54 # no more there after |
4286
949516072388
test-hook: use printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4085
diff
changeset
|
55 echo 'pretxncommit.forbid0 = hg tip -q' >> .hg/hgrc |
949516072388
test-hook: use printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4085
diff
changeset
|
56 echo 'pretxncommit.forbid1 = python ../printenv.py pretxncommit.forbid 1' >> .hg/hgrc |
1734
9488d53233b5
tests for new hooks. fix things i found when writing tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1481
diff
changeset
|
57 echo z > z |
9488d53233b5
tests for new hooks. fix things i found when writing tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1481
diff
changeset
|
58 hg add z |
9488d53233b5
tests for new hooks. fix things i found when writing tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1481
diff
changeset
|
59 hg -q tip |
9488d53233b5
tests for new hooks. fix things i found when writing tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1481
diff
changeset
|
60 hg commit -m 'fail' -d '4 0' |
9488d53233b5
tests for new hooks. fix things i found when writing tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1481
diff
changeset
|
61 hg -q tip |
9488d53233b5
tests for new hooks. fix things i found when writing tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1481
diff
changeset
|
62 |
9488d53233b5
tests for new hooks. fix things i found when writing tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1481
diff
changeset
|
63 # precommit hook can prevent commit |
4286
949516072388
test-hook: use printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4085
diff
changeset
|
64 echo 'precommit.forbid = python ../printenv.py precommit.forbid 1' >> .hg/hgrc |
1734
9488d53233b5
tests for new hooks. fix things i found when writing tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1481
diff
changeset
|
65 hg commit -m 'fail' -d '4 0' |
9488d53233b5
tests for new hooks. fix things i found when writing tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1481
diff
changeset
|
66 hg -q tip |
9488d53233b5
tests for new hooks. fix things i found when writing tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1481
diff
changeset
|
67 |
2266
3f7692b0ff13
hooks: add preupdate and update hooks.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2227
diff
changeset
|
68 # preupdate hook can prevent update |
4286
949516072388
test-hook: use printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4085
diff
changeset
|
69 echo 'preupdate = python ../printenv.py preupdate' >> .hg/hgrc |
2266
3f7692b0ff13
hooks: add preupdate and update hooks.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2227
diff
changeset
|
70 hg update 1 |
3f7692b0ff13
hooks: add preupdate and update hooks.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2227
diff
changeset
|
71 |
3f7692b0ff13
hooks: add preupdate and update hooks.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2227
diff
changeset
|
72 # update hook |
4286
949516072388
test-hook: use printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4085
diff
changeset
|
73 echo 'update = python ../printenv.py update' >> .hg/hgrc |
2266
3f7692b0ff13
hooks: add preupdate and update hooks.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2227
diff
changeset
|
74 hg update |
3f7692b0ff13
hooks: add preupdate and update hooks.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2227
diff
changeset
|
75 |
1734
9488d53233b5
tests for new hooks. fix things i found when writing tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1481
diff
changeset
|
76 # prechangegroup hook can prevent incoming changes |
9488d53233b5
tests for new hooks. fix things i found when writing tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1481
diff
changeset
|
77 cd ../b |
9488d53233b5
tests for new hooks. fix things i found when writing tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1481
diff
changeset
|
78 hg -q tip |
9488d53233b5
tests for new hooks. fix things i found when writing tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1481
diff
changeset
|
79 echo '[hooks]' > .hg/hgrc |
4286
949516072388
test-hook: use printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4085
diff
changeset
|
80 echo 'prechangegroup.forbid = python ../printenv.py prechangegroup.forbid 1' >> .hg/hgrc |
1734
9488d53233b5
tests for new hooks. fix things i found when writing tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1481
diff
changeset
|
81 hg pull ../a |
9488d53233b5
tests for new hooks. fix things i found when writing tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1481
diff
changeset
|
82 |
9488d53233b5
tests for new hooks. fix things i found when writing tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1481
diff
changeset
|
83 # pretxnchangegroup hook can see incoming changes, can roll back txn, |
9488d53233b5
tests for new hooks. fix things i found when writing tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1481
diff
changeset
|
84 # incoming changes no longer there after |
9488d53233b5
tests for new hooks. fix things i found when writing tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1481
diff
changeset
|
85 echo '[hooks]' > .hg/hgrc |
4286
949516072388
test-hook: use printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4085
diff
changeset
|
86 echo 'pretxnchangegroup.forbid0 = hg tip -q' >> .hg/hgrc |
949516072388
test-hook: use printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4085
diff
changeset
|
87 echo 'pretxnchangegroup.forbid1 = python ../printenv.py pretxnchangegroup.forbid 1' >> .hg/hgrc |
1734
9488d53233b5
tests for new hooks. fix things i found when writing tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1481
diff
changeset
|
88 hg pull ../a |
9488d53233b5
tests for new hooks. fix things i found when writing tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1481
diff
changeset
|
89 hg -q tip |
1736
50de0887bbcd
add preoutgoing and outgoing hooks.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1734
diff
changeset
|
90 |
50de0887bbcd
add preoutgoing and outgoing hooks.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1734
diff
changeset
|
91 # outgoing hooks can see env vars |
50de0887bbcd
add preoutgoing and outgoing hooks.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1734
diff
changeset
|
92 rm .hg/hgrc |
50de0887bbcd
add preoutgoing and outgoing hooks.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1734
diff
changeset
|
93 echo '[hooks]' > ../a/.hg/hgrc |
4286
949516072388
test-hook: use printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4085
diff
changeset
|
94 echo 'preoutgoing = python ../printenv.py preoutgoing' >> ../a/.hg/hgrc |
949516072388
test-hook: use printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4085
diff
changeset
|
95 echo 'outgoing = python ../printenv.py outgoing' >> ../a/.hg/hgrc |
1736
50de0887bbcd
add preoutgoing and outgoing hooks.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1734
diff
changeset
|
96 hg pull ../a |
2227
4f072bb06e89
deprecate undo command, replace with rollback command.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2221
diff
changeset
|
97 hg rollback |
1736
50de0887bbcd
add preoutgoing and outgoing hooks.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1734
diff
changeset
|
98 |
50de0887bbcd
add preoutgoing and outgoing hooks.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1734
diff
changeset
|
99 # preoutgoing hook can prevent outgoing changes |
4286
949516072388
test-hook: use printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4085
diff
changeset
|
100 echo 'preoutgoing.forbid = python ../printenv.py preoutgoing.forbid 1' >> ../a/.hg/hgrc |
1736
50de0887bbcd
add preoutgoing and outgoing hooks.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1734
diff
changeset
|
101 hg pull ../a |
50de0887bbcd
add preoutgoing and outgoing hooks.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1734
diff
changeset
|
102 |
2155
ff255b41b4aa
support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1933
diff
changeset
|
103 cat > hooktests.py <<EOF |
ff255b41b4aa
support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1933
diff
changeset
|
104 from mercurial import util |
ff255b41b4aa
support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1933
diff
changeset
|
105 |
ff255b41b4aa
support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1933
diff
changeset
|
106 uncallable = 0 |
ff255b41b4aa
support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1933
diff
changeset
|
107 |
ff255b41b4aa
support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1933
diff
changeset
|
108 def printargs(args): |
ff255b41b4aa
support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1933
diff
changeset
|
109 args.pop('ui', None) |
ff255b41b4aa
support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1933
diff
changeset
|
110 args.pop('repo', None) |
ff255b41b4aa
support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1933
diff
changeset
|
111 a = list(args.items()) |
ff255b41b4aa
support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1933
diff
changeset
|
112 a.sort() |
ff255b41b4aa
support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1933
diff
changeset
|
113 print 'hook args:' |
ff255b41b4aa
support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1933
diff
changeset
|
114 for k, v in a: |
ff255b41b4aa
support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1933
diff
changeset
|
115 print ' ', k, v |
ff255b41b4aa
support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1933
diff
changeset
|
116 |
ff255b41b4aa
support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1933
diff
changeset
|
117 def passhook(**args): |
ff255b41b4aa
support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1933
diff
changeset
|
118 printargs(args) |
ff255b41b4aa
support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1933
diff
changeset
|
119 |
ff255b41b4aa
support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1933
diff
changeset
|
120 def failhook(**args): |
ff255b41b4aa
support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1933
diff
changeset
|
121 printargs(args) |
2221
05b6c13f43c6
reverse sense of return value from python hooks.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2164
diff
changeset
|
122 return True |
2155
ff255b41b4aa
support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1933
diff
changeset
|
123 |
ff255b41b4aa
support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1933
diff
changeset
|
124 class LocalException(Exception): |
ff255b41b4aa
support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1933
diff
changeset
|
125 pass |
ff255b41b4aa
support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1933
diff
changeset
|
126 |
ff255b41b4aa
support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1933
diff
changeset
|
127 def raisehook(**args): |
ff255b41b4aa
support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1933
diff
changeset
|
128 raise LocalException('exception from hook') |
ff255b41b4aa
support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1933
diff
changeset
|
129 |
ff255b41b4aa
support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1933
diff
changeset
|
130 def aborthook(**args): |
ff255b41b4aa
support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1933
diff
changeset
|
131 raise util.Abort('raise abort from hook') |
ff255b41b4aa
support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1933
diff
changeset
|
132 |
ff255b41b4aa
support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1933
diff
changeset
|
133 def brokenhook(**args): |
ff255b41b4aa
support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1933
diff
changeset
|
134 return 1 + {} |
ff255b41b4aa
support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1933
diff
changeset
|
135 |
ff255b41b4aa
support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1933
diff
changeset
|
136 class container: |
ff255b41b4aa
support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1933
diff
changeset
|
137 unreachable = 1 |
ff255b41b4aa
support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1933
diff
changeset
|
138 EOF |
ff255b41b4aa
support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1933
diff
changeset
|
139 |
ff255b41b4aa
support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1933
diff
changeset
|
140 echo '# test python hooks' |
2164
cbd458228a96
Applied $PWD fix (changeset 278f9b13c39a) to tests/test-hook, too.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
2155
diff
changeset
|
141 PYTHONPATH="`pwd`:$PYTHONPATH" |
2155
ff255b41b4aa
support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1933
diff
changeset
|
142 export PYTHONPATH |
ff255b41b4aa
support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1933
diff
changeset
|
143 |
ff255b41b4aa
support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1933
diff
changeset
|
144 echo '[hooks]' > ../a/.hg/hgrc |
ff255b41b4aa
support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1933
diff
changeset
|
145 echo 'preoutgoing.broken = python:hooktests.brokenhook' >> ../a/.hg/hgrc |
ff255b41b4aa
support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1933
diff
changeset
|
146 hg pull ../a 2>&1 | grep 'raised an exception' |
ff255b41b4aa
support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1933
diff
changeset
|
147 |
ff255b41b4aa
support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1933
diff
changeset
|
148 echo '[hooks]' > ../a/.hg/hgrc |
ff255b41b4aa
support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1933
diff
changeset
|
149 echo 'preoutgoing.raise = python:hooktests.raisehook' >> ../a/.hg/hgrc |
ff255b41b4aa
support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1933
diff
changeset
|
150 hg pull ../a 2>&1 | grep 'raised an exception' |
ff255b41b4aa
support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1933
diff
changeset
|
151 |
ff255b41b4aa
support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1933
diff
changeset
|
152 echo '[hooks]' > ../a/.hg/hgrc |
ff255b41b4aa
support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1933
diff
changeset
|
153 echo 'preoutgoing.abort = python:hooktests.aborthook' >> ../a/.hg/hgrc |
ff255b41b4aa
support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1933
diff
changeset
|
154 hg pull ../a |
ff255b41b4aa
support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1933
diff
changeset
|
155 |
ff255b41b4aa
support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1933
diff
changeset
|
156 echo '[hooks]' > ../a/.hg/hgrc |
ff255b41b4aa
support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1933
diff
changeset
|
157 echo 'preoutgoing.fail = python:hooktests.failhook' >> ../a/.hg/hgrc |
ff255b41b4aa
support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1933
diff
changeset
|
158 hg pull ../a |
ff255b41b4aa
support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1933
diff
changeset
|
159 |
ff255b41b4aa
support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1933
diff
changeset
|
160 echo '[hooks]' > ../a/.hg/hgrc |
ff255b41b4aa
support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1933
diff
changeset
|
161 echo 'preoutgoing.uncallable = python:hooktests.uncallable' >> ../a/.hg/hgrc |
ff255b41b4aa
support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1933
diff
changeset
|
162 hg pull ../a |
ff255b41b4aa
support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1933
diff
changeset
|
163 |
ff255b41b4aa
support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1933
diff
changeset
|
164 echo '[hooks]' > ../a/.hg/hgrc |
ff255b41b4aa
support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1933
diff
changeset
|
165 echo 'preoutgoing.nohook = python:hooktests.nohook' >> ../a/.hg/hgrc |
ff255b41b4aa
support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1933
diff
changeset
|
166 hg pull ../a |
ff255b41b4aa
support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1933
diff
changeset
|
167 |
ff255b41b4aa
support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1933
diff
changeset
|
168 echo '[hooks]' > ../a/.hg/hgrc |
ff255b41b4aa
support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1933
diff
changeset
|
169 echo 'preoutgoing.nomodule = python:nomodule' >> ../a/.hg/hgrc |
ff255b41b4aa
support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1933
diff
changeset
|
170 hg pull ../a |
ff255b41b4aa
support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1933
diff
changeset
|
171 |
ff255b41b4aa
support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1933
diff
changeset
|
172 echo '[hooks]' > ../a/.hg/hgrc |
ff255b41b4aa
support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1933
diff
changeset
|
173 echo 'preoutgoing.badmodule = python:nomodule.nowhere' >> ../a/.hg/hgrc |
ff255b41b4aa
support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1933
diff
changeset
|
174 hg pull ../a |
ff255b41b4aa
support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1933
diff
changeset
|
175 |
ff255b41b4aa
support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1933
diff
changeset
|
176 echo '[hooks]' > ../a/.hg/hgrc |
ff255b41b4aa
support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1933
diff
changeset
|
177 echo 'preoutgoing.unreachable = python:hooktests.container.unreachable' >> ../a/.hg/hgrc |
ff255b41b4aa
support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1933
diff
changeset
|
178 hg pull ../a |
ff255b41b4aa
support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1933
diff
changeset
|
179 |
ff255b41b4aa
support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1933
diff
changeset
|
180 echo '[hooks]' > ../a/.hg/hgrc |
ff255b41b4aa
support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1933
diff
changeset
|
181 echo 'preoutgoing.pass = python:hooktests.passhook' >> ../a/.hg/hgrc |
ff255b41b4aa
support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1933
diff
changeset
|
182 hg pull ../a |
ff255b41b4aa
support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1933
diff
changeset
|
183 |
ff255b41b4aa
support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1933
diff
changeset
|
184 echo '# make sure --traceback works' |
ff255b41b4aa
support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1933
diff
changeset
|
185 echo '[hooks]' > .hg/hgrc |
ff255b41b4aa
support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1933
diff
changeset
|
186 echo 'commit.abort = python:hooktests.aborthook' >> .hg/hgrc |
ff255b41b4aa
support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1933
diff
changeset
|
187 |
ff255b41b4aa
support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1933
diff
changeset
|
188 echo a >> a |
ff255b41b4aa
support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1933
diff
changeset
|
189 hg --traceback commit -A -m a 2>&1 | grep '^Traceback' |
ff255b41b4aa
support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1933
diff
changeset
|
190 |
4070
961ccb615cf7
Handle functions as the value of a hooks.<name> config variable
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
2673
diff
changeset
|
191 cd .. |
961ccb615cf7
Handle functions as the value of a hooks.<name> config variable
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
2673
diff
changeset
|
192 hg init c |
961ccb615cf7
Handle functions as the value of a hooks.<name> config variable
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
2673
diff
changeset
|
193 cd c |
961ccb615cf7
Handle functions as the value of a hooks.<name> config variable
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
2673
diff
changeset
|
194 |
961ccb615cf7
Handle functions as the value of a hooks.<name> config variable
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
2673
diff
changeset
|
195 cat > hookext.py <<EOF |
961ccb615cf7
Handle functions as the value of a hooks.<name> config variable
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
2673
diff
changeset
|
196 def autohook(**args): |
961ccb615cf7
Handle functions as the value of a hooks.<name> config variable
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
2673
diff
changeset
|
197 print "Automatically installed hook" |
961ccb615cf7
Handle functions as the value of a hooks.<name> config variable
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
2673
diff
changeset
|
198 |
961ccb615cf7
Handle functions as the value of a hooks.<name> config variable
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
2673
diff
changeset
|
199 def reposetup(ui, repo): |
961ccb615cf7
Handle functions as the value of a hooks.<name> config variable
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
2673
diff
changeset
|
200 repo.ui.setconfig("hooks", "commit.auto", autohook) |
961ccb615cf7
Handle functions as the value of a hooks.<name> config variable
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
2673
diff
changeset
|
201 EOF |
961ccb615cf7
Handle functions as the value of a hooks.<name> config variable
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
2673
diff
changeset
|
202 echo '[extensions]' >> .hg/hgrc |
961ccb615cf7
Handle functions as the value of a hooks.<name> config variable
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
2673
diff
changeset
|
203 echo 'hookext = hookext.py' >> .hg/hgrc |
961ccb615cf7
Handle functions as the value of a hooks.<name> config variable
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
2673
diff
changeset
|
204 |
961ccb615cf7
Handle functions as the value of a hooks.<name> config variable
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
2673
diff
changeset
|
205 touch foo |
961ccb615cf7
Handle functions as the value of a hooks.<name> config variable
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
2673
diff
changeset
|
206 hg add foo |
961ccb615cf7
Handle functions as the value of a hooks.<name> config variable
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
2673
diff
changeset
|
207 hg ci -m 'add foo' |
961ccb615cf7
Handle functions as the value of a hooks.<name> config variable
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
2673
diff
changeset
|
208 echo >> foo |
961ccb615cf7
Handle functions as the value of a hooks.<name> config variable
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
2673
diff
changeset
|
209 hg ci --debug -m 'change foo' | sed -e 's/ at .*>/>/' |
961ccb615cf7
Handle functions as the value of a hooks.<name> config variable
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
2673
diff
changeset
|
210 |
4085
719488a98ebe
Fix hg showconfig traceback with values that aren't strings
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4070
diff
changeset
|
211 hg showconfig hooks | sed -e 's/ at .*>/>/' |
719488a98ebe
Fix hg showconfig traceback with values that aren't strings
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4070
diff
changeset
|
212 |
1736
50de0887bbcd
add preoutgoing and outgoing hooks.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1734
diff
changeset
|
213 exit 0 |