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