comparison hgext/amend.py @ 33404:0d5afd360e9e

amend: new extension providing the amend command Various third parties have implemented the `amend` command, which is in high demand. This patch adds it as an experimental extension so its interface could be formalized in core directly. Since `commit --amend` is basically what `amend` should do. The command is just a thin wrapper around `commit --amend` and just prevent the editor from popping up by passing `--message`.
author Jun Wu <quark@fb.com>
date Tue, 11 Jul 2017 20:53:55 -0700
parents
children 530b7361e3a9
comparison
equal deleted inserted replaced
33403:1bb209d08a34 33404:0d5afd360e9e
1 # amend.py - provide the amend command
2 #
3 # Copyright 2017 Facebook, Inc.
4 #
5 # This software may be used and distributed according to the terms of the
6 # GNU General Public License version 2 or any later version.
7 """provide the amend command (EXPERIMENTAL)
8
9 This extension provides an ``amend`` command that is similar to
10 ``commit --amend`` but does not prompt an editor.
11 """
12
13 from __future__ import absolute_import
14
15 from mercurial.i18n import _
16 from mercurial import (
17 cmdutil,
18 commands,
19 registrar,
20 )
21
22 # Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for
23 # extensions which SHIP WITH MERCURIAL. Non-mainline extensions should
24 # be specifying the version(s) of Mercurial they are tested with, or
25 # leave the attribute unspecified.
26 testedwith = 'ships-with-hg-core'
27
28 cmdtable = {}
29 command = registrar.command(cmdtable)
30
31 @command('amend',
32 [('A', 'addremove', None,
33 _('mark new/missing files as added/removed before committing')),
34 ('e', 'edit', None, _('invoke editor on commit messages')),
35 ('i', 'interactive', None, _('use interactive mode')),
36 ] + cmdutil.walkopts + cmdutil.commitopts + cmdutil.commitopts2,
37 _('[OPTION]... [FILE]...'),
38 inferrepo=True)
39 def amend(ui, repo, *pats, **opts):
40 """amend the working copy parent with all or specified outstanding changes
41
42 Similar to :hg:`commit --amend`, but reuse the commit message without
43 invoking editor, unless ``--edit`` was set.
44
45 See :hg:`help commit` for more details.
46 """
47 with repo.wlock(), repo.lock():
48 if not opts.get('logfile'):
49 opts['message'] = opts.get('message') or repo['.'].description()
50 opts['amend'] = True
51 return commands._docommit(ui, repo, *pats, **opts)