##// END OF EJS Templates
bookflow: fix bullet list indentation in docstring
Ludovic Chabant -
r52915:745409f9 default
parent child Browse files
Show More
@@ -1,127 +1,127 b''
1 1 """implements bookmark-based branching (EXPERIMENTAL)
2 2
3 - Disables creation of new branches (config: enable_branches=False).
4 - Requires an active bookmark on commit (config: require_bookmark=True).
5 - Doesn't move the active bookmark on update, only on commit.
6 - Requires '--rev' for moving an existing bookmark.
7 - Protects special bookmarks (config: protect=@).
3 - Disables creation of new branches (config: enable_branches=False).
4 - Requires an active bookmark on commit (config: require_bookmark=True).
5 - Doesn't move the active bookmark on update, only on commit.
6 - Requires '--rev' for moving an existing bookmark.
7 - Protects special bookmarks (config: protect=@).
8 8
9 flow related commands
9 flow related commands
10 10
11 11 :hg book NAME: create a new bookmark
12 12 :hg book NAME -r REV: move bookmark to revision (fast-forward)
13 13 :hg up|co NAME: switch to bookmark
14 14 :hg push -B .: push active bookmark
15 15 """
16 16
17 17 from __future__ import annotations
18 18
19 19 from mercurial.i18n import _
20 20 from mercurial import (
21 21 bookmarks,
22 22 commands,
23 23 error,
24 24 extensions,
25 25 registrar,
26 26 )
27 27
28 28 MY_NAME = b'bookflow'
29 29
30 30 configtable = {}
31 31 configitem = registrar.configitem(configtable)
32 32
33 33 configitem(MY_NAME, b'protect', [b'@'])
34 34 configitem(MY_NAME, b'require-bookmark', True)
35 35 configitem(MY_NAME, b'enable-branches', False)
36 36
37 37 cmdtable = {}
38 38 command = registrar.command(cmdtable)
39 39
40 40
41 41 def commit_hook(ui, repo, **kwargs):
42 42 active = repo._bookmarks.active
43 43 if active:
44 44 if active in ui.configlist(MY_NAME, b'protect'):
45 45 raise error.Abort(
46 46 _(b'cannot commit, bookmark %s is protected') % active
47 47 )
48 48 if not cwd_at_bookmark(repo, active):
49 49 raise error.Abort(
50 50 _(
51 51 b'cannot commit, working directory out of sync with active bookmark'
52 52 ),
53 53 hint=_(b"run 'hg up %s'") % active,
54 54 )
55 55 elif ui.configbool(MY_NAME, b'require-bookmark', True):
56 56 raise error.Abort(_(b'cannot commit without an active bookmark'))
57 57 return 0
58 58
59 59
60 60 def bookmarks_update(orig, repo, parents, node):
61 61 if len(parents) == 2:
62 62 # called during commit
63 63 return orig(repo, parents, node)
64 64 else:
65 65 # called during update
66 66 return False
67 67
68 68
69 69 def bookmarks_addbookmarks(
70 70 orig, repo, tr, names, rev=None, force=False, inactive=False
71 71 ):
72 72 if not rev:
73 73 marks = repo._bookmarks
74 74 for name in names:
75 75 if name in marks:
76 76 raise error.Abort(
77 77 _(
78 78 b"bookmark %s already exists, to move use the --rev option"
79 79 )
80 80 % name
81 81 )
82 82 return orig(repo, tr, names, rev, force, inactive)
83 83
84 84
85 85 def commands_commit(orig, ui, repo, *args, **opts):
86 86 commit_hook(ui, repo)
87 87 return orig(ui, repo, *args, **opts)
88 88
89 89
90 90 def commands_pull(orig, ui, repo, *args, **opts):
91 91 rc = orig(ui, repo, *args, **opts)
92 92 active = repo._bookmarks.active
93 93 if active and not cwd_at_bookmark(repo, active):
94 94 ui.warn(
95 95 _(
96 96 b"working directory out of sync with active bookmark, run "
97 97 b"'hg up %s'"
98 98 )
99 99 % active
100 100 )
101 101 return rc
102 102
103 103
104 104 def commands_branch(orig, ui, repo, label=None, **opts):
105 105 if label and not opts.get('clean') and not opts.get('rev'):
106 106 raise error.Abort(
107 107 _(
108 108 b"creating named branches is disabled and you should use bookmarks"
109 109 ),
110 110 hint=b"see 'hg help bookflow'",
111 111 )
112 112 return orig(ui, repo, label, **opts)
113 113
114 114
115 115 def cwd_at_bookmark(repo, mark):
116 116 mark_id = repo._bookmarks[mark]
117 117 cur_id = repo.lookup(b'.')
118 118 return cur_id == mark_id
119 119
120 120
121 121 def uisetup(ui):
122 122 extensions.wrapfunction(bookmarks, 'update', bookmarks_update)
123 123 extensions.wrapfunction(bookmarks, 'addbookmarks', bookmarks_addbookmarks)
124 124 extensions.wrapcommand(commands.table, b'commit', commands_commit)
125 125 extensions.wrapcommand(commands.table, b'pull', commands_pull)
126 126 if not ui.configbool(MY_NAME, b'enable-branches'):
127 127 extensions.wrapcommand(commands.table, b'branch', commands_branch)
General Comments 0
You need to be logged in to leave comments. Login now