Mercurial > hg
annotate hgext/hooklib/enforce_draft_commits.py @ 51700:7f0cb9ee0534
Backout accidental publication of a large range of revisions
I accidentally published 25e7f9dcad0f::bd1483fd7088, this is the inverse.
author | Raphaël Gomès <rgomes@octobus.net> |
---|---|
date | Tue, 23 Jul 2024 10:02:46 +0200 |
parents | 6000f5b25c9b |
children | f4733654f144 |
rev | line source |
---|---|
44413
4cabeea6d214
hgext: start building a library for simple hooks
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
1 # Copyright 2020 Joerg Sonnenberger <joerg@bec.de> |
4cabeea6d214
hgext: start building a library for simple hooks
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
2 # |
4cabeea6d214
hgext: start building a library for simple hooks
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
3 # This software may be used and distributed according to the terms of the |
4cabeea6d214
hgext: start building a library for simple hooks
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
4 # GNU General Public License version 2 or any later version. |
4cabeea6d214
hgext: start building a library for simple hooks
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
5 |
4cabeea6d214
hgext: start building a library for simple hooks
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
6 """enforce_draft_commits us a hook to ensure that all new changesets are |
4cabeea6d214
hgext: start building a library for simple hooks
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
7 in the draft phase. This allows enforcing policies for work-in-progress |
4cabeea6d214
hgext: start building a library for simple hooks
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
8 changes in overlay repositories, i.e. a shared hidden repositories with |
4cabeea6d214
hgext: start building a library for simple hooks
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
9 different views for work-in-progress code and public history. |
4cabeea6d214
hgext: start building a library for simple hooks
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
10 |
4cabeea6d214
hgext: start building a library for simple hooks
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
11 Usage: |
4cabeea6d214
hgext: start building a library for simple hooks
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
12 [hooks] |
4cabeea6d214
hgext: start building a library for simple hooks
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
13 pretxnclose-phase.enforce_draft_commits = \ |
4cabeea6d214
hgext: start building a library for simple hooks
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
14 python:hgext.hooklib.enforce_draft_commits.hook |
4cabeea6d214
hgext: start building a library for simple hooks
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
15 """ |
4cabeea6d214
hgext: start building a library for simple hooks
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
16 |
4cabeea6d214
hgext: start building a library for simple hooks
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
17 |
4cabeea6d214
hgext: start building a library for simple hooks
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
18 from mercurial.i18n import _ |
4cabeea6d214
hgext: start building a library for simple hooks
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
19 from mercurial import ( |
4cabeea6d214
hgext: start building a library for simple hooks
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
20 error, |
4cabeea6d214
hgext: start building a library for simple hooks
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
21 pycompat, |
4cabeea6d214
hgext: start building a library for simple hooks
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
22 ) |
4cabeea6d214
hgext: start building a library for simple hooks
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
23 |
4cabeea6d214
hgext: start building a library for simple hooks
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
24 |
4cabeea6d214
hgext: start building a library for simple hooks
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
25 def hook(ui, repo, hooktype, node=None, **kwargs): |
4cabeea6d214
hgext: start building a library for simple hooks
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
26 if hooktype != b"pretxnclose-phase": |
4cabeea6d214
hgext: start building a library for simple hooks
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
27 raise error.Abort( |
4cabeea6d214
hgext: start building a library for simple hooks
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
28 _(b'Unsupported hook type %r') % pycompat.bytestr(hooktype) |
4cabeea6d214
hgext: start building a library for simple hooks
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
29 ) |
4cabeea6d214
hgext: start building a library for simple hooks
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
30 ctx = repo.unfiltered()[node] |
4cabeea6d214
hgext: start building a library for simple hooks
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
31 if kwargs['oldphase']: |
4cabeea6d214
hgext: start building a library for simple hooks
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
32 raise error.Abort( |
4cabeea6d214
hgext: start building a library for simple hooks
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
33 _(b'Phase change from %r to %r for %s rejected') |
4cabeea6d214
hgext: start building a library for simple hooks
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
34 % ( |
4cabeea6d214
hgext: start building a library for simple hooks
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
35 pycompat.bytestr(kwargs['oldphase']), |
4cabeea6d214
hgext: start building a library for simple hooks
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
36 pycompat.bytestr(kwargs['phase']), |
4cabeea6d214
hgext: start building a library for simple hooks
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
37 ctx, |
4cabeea6d214
hgext: start building a library for simple hooks
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
38 ) |
4cabeea6d214
hgext: start building a library for simple hooks
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
39 ) |
4cabeea6d214
hgext: start building a library for simple hooks
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
40 elif kwargs['phase'] != b'draft': |
4cabeea6d214
hgext: start building a library for simple hooks
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
41 raise error.Abort( |
4cabeea6d214
hgext: start building a library for simple hooks
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
42 _(b'New changeset %s in phase %r rejected') |
4cabeea6d214
hgext: start building a library for simple hooks
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
43 % (ctx, pycompat.bytestr(kwargs['phase'])) |
4cabeea6d214
hgext: start building a library for simple hooks
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
44 ) |