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