| 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 annotations |
| 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 = b'ships-with-hg-core' |
| 27 |
|
| 28 |
cmdtable = {} |
| 29 |
command = registrar.command(cmdtable) |
| 30 |
|
| 31 |
|
| 32 |
@command( |
| 33 |
b'amend', |
| 34 |
[ |
| 35 |
( |
| 36 |
b'A', |
| 37 |
b'addremove', |
| 38 |
None, |
| 39 |
_(b'mark new/missing files as added/removed before committing'), |
| 40 |
), |
| 41 |
(b'e', b'edit', None, _(b'invoke editor on commit messages')), |
| 42 |
(b'i', b'interactive', None, _(b'use interactive mode')), |
| 43 |
( |
| 44 |
b'', |
| 45 |
b'close-branch', |
| 46 |
None, |
| 47 |
_(b'mark a branch as closed, hiding it from the branch list'), |
| 48 |
), |
| 49 |
(b's', b'secret', None, _(b'use the secret phase for committing')), |
| 50 |
(b'', b'draft', None, _(b'use the draft phase for committing')), |
| 51 |
(b'n', b'note', b'', _(b'store a note on the amend')), |
| 52 |
] |
| 53 |
+ cmdutil.walkopts |
| 54 |
+ cmdutil.commitopts |
| 55 |
+ cmdutil.commitopts2 |
| 56 |
+ cmdutil.commitopts3, |
| 57 |
_(b'[OPTION]... [FILE]...'), |
| 58 |
helpcategory=command.CATEGORY_COMMITTING, |
| 59 |
inferrepo=True, |
| 60 |
) |
| 61 |
def amend(ui, repo, *pats, **opts): |
| 62 |
"""amend the working copy parent with all or specified outstanding changes |
| 63 |
|
| 64 |
Similar to :hg:`commit --amend`, but reuse the commit message without |
| 65 |
invoking editor, unless ``--edit`` was set. |
| 66 |
|
| 67 |
See :hg:`help commit` for more details. |
| 68 |
""" |
| 69 |
cmdutil.check_at_most_one_arg(opts, 'draft', 'secret') |
| 70 |
cmdutil.check_note_size(opts) |
| 71 |
|
| 72 |
with repo.wlock(), repo.lock(): |
| 73 |
if not opts.get('logfile'): |
| 74 |
opts['message'] = opts.get('message') or repo[b'.'].description() |
| 75 |
opts['amend'] = True |
| 76 |
return commands._docommit(ui, repo, *pats, **opts) |