Debian Codegraph @

hgext/hooklib/enforce_draft_commits.py

raw
1 # Copyright 2020 Joerg Sonnenberger <[email protected]>
2 #
3 # This software may be used and distributed according to the terms of the
4 # GNU General Public License version 2 or any later version.
5
6 """enforce_draft_commits us a hook to ensure that all new changesets are
7 in the draft phase. This allows enforcing policies for work-in-progress
8 changes in overlay repositories, i.e. a shared hidden repositories with
9 different views for work-in-progress code and public history.
10
11 Usage:
12 [hooks]
13 pretxnclose-phase.enforce_draft_commits = \
14 python:hgext.hooklib.enforce_draft_commits.hook
15 """
16
17 from __future__ import annotations
18
19 from mercurial.i18n import _
20 from mercurial import (
21 error,
22 pycompat,
23 )
24
25
26 def hook(ui, repo, hooktype, node=None, **kwargs):
27 if hooktype != b"pretxnclose-phase":
28 raise error.Abort(
29 _(b'Unsupported hook type %r') % pycompat.bytestr(hooktype)
30 )
31 ctx = repo.unfiltered()[node]
32 if kwargs['oldphase']:
33 raise error.Abort(
34 _(b'Phase change from %r to %r for %s rejected')
35 % (
36 pycompat.bytestr(kwargs['oldphase']),
37 pycompat.bytestr(kwargs['phase']),
38 ctx,
39 )
40 )
41 elif kwargs['phase'] != b'draft':
42 raise error.Abort(
43 _(b'New changeset %s in phase %r rejected')
44 % (ctx, pycompat.bytestr(kwargs['phase']))
45 )