Mercurial > public > mercurial-scm > hg
comparison hgext/uncommit.py @ 41750:1040d54eb7eb
uncommit: add config option to keep commit by default
We have a Google-internal extension that keeps track of "review units"
(like Phabricator reviews, or Gerrit's Change-Id). This information is
stored outside of the commit. It is updated with rewrites. Every now
and then we get reports from users who are confused because `hg
uncommit` lost track of their review. Keeping the empty commit by
default would reduce this confusion. It may also cause confusion about
the empty commit. This patch adds a config option that lets us easily
test both behaviors on our users.
Differential Revision: https://phab.mercurial-scm.org/D5970
author | Martin von Zweigbergk <martinvonz@google.com> |
---|---|
date | Fri, 15 Feb 2019 10:39:45 -0800 |
parents | 83d294c71f1e |
children | bf22e370ae9a |
comparison
equal
deleted
inserted
replaced
41749:f96988680afe | 41750:1040d54eb7eb |
---|---|
40 | 40 |
41 configtable = {} | 41 configtable = {} |
42 configitem = registrar.configitem(configtable) | 42 configitem = registrar.configitem(configtable) |
43 | 43 |
44 configitem('experimental', 'uncommitondirtywdir', | 44 configitem('experimental', 'uncommitondirtywdir', |
45 default=False, | |
46 ) | |
47 configitem('experimental', 'uncommit.keep', | |
45 default=False, | 48 default=False, |
46 ) | 49 ) |
47 | 50 |
48 # Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for | 51 # Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for |
49 # extensions which SHIP WITH MERCURIAL. Non-mainline extensions should | 52 # extensions which SHIP WITH MERCURIAL. Non-mainline extensions should |
134 if (src not in newctx or dst in newctx or ds[dst] != 'a'): | 137 if (src not in newctx or dst in newctx or ds[dst] != 'a'): |
135 src = None | 138 src = None |
136 ds.copy(src, dst) | 139 ds.copy(src, dst) |
137 | 140 |
138 @command('uncommit', | 141 @command('uncommit', |
139 [('', 'keep', False, _('allow an empty commit after uncommiting')), | 142 [('', 'keep', None, _('allow an empty commit after uncommiting')), |
140 ] + commands.walkopts, | 143 ] + commands.walkopts, |
141 _('[OPTION]... [FILE]...'), | 144 _('[OPTION]... [FILE]...'), |
142 helpcategory=command.CATEGORY_CHANGE_MANAGEMENT) | 145 helpcategory=command.CATEGORY_CHANGE_MANAGEMENT) |
143 def uncommit(ui, repo, *pats, **opts): | 146 def uncommit(ui, repo, *pats, **opts): |
144 """uncommit part or all of a local changeset | 147 """uncommit part or all of a local changeset |
163 if len(old.parents()) > 1: | 166 if len(old.parents()) > 1: |
164 raise error.Abort(_("cannot uncommit merge changeset")) | 167 raise error.Abort(_("cannot uncommit merge changeset")) |
165 | 168 |
166 with repo.transaction('uncommit'): | 169 with repo.transaction('uncommit'): |
167 match = scmutil.match(old, pats, opts) | 170 match = scmutil.match(old, pats, opts) |
168 keepcommit = opts.get('keep') or pats | 171 keepcommit = pats |
172 if not keepcommit: | |
173 if opts.get('keep') is not None: | |
174 keepcommit = opts.get('keep') | |
175 else: | |
176 keepcommit = ui.configbool('experimental', 'uncommit.keep') | |
169 newid = _commitfiltered(repo, old, match, keepcommit) | 177 newid = _commitfiltered(repo, old, match, keepcommit) |
170 if newid is None: | 178 if newid is None: |
171 ui.status(_("nothing to uncommit\n")) | 179 ui.status(_("nothing to uncommit\n")) |
172 return 1 | 180 return 1 |
173 | 181 |