tweakdefaults: move commit -M to core

Summary: Clean it up a bit too.

Reviewed By: ikostia

Differential Revision: D10359624

fbshipit-source-id: 287bd9013fdd6eb33304def7e4f6afdd9f618ef0
This commit is contained in:
Phil Cohen 2018-10-15 10:30:18 -07:00 committed by Facebook Github Bot
parent f18bd9714d
commit 1d8a354bfb
5 changed files with 60 additions and 50 deletions

View File

@ -169,10 +169,6 @@ def extsetup(ui):
wrapblame()
entry = wrapcommand(commands.table, "commit", commitcmd)
options = entry[1]
options.insert(
9, ("M", "reuse-message", "", _("reuse commit message from REV"), _("REV"))
)
opawarerebase = markermetadatawritingcommand(ui, _rebase, "rebase")
wrapcommand(rebase.cmdtable, "rebase", opawarerebase)
wrapfunction(scmutil, "cleanupnodes", cleanupnodeswrapper)
@ -458,20 +454,6 @@ def commitcmd(orig, ui, repo, *pats, **opts):
and not ui.configbool("tweakdefaults", "amendkeepdate")
):
opts["date"] = currentdate()
rev = opts.get("reuse_message")
if rev:
invalidargs = ["message", "logfile"]
currentinvalidargs = [ia for ia in invalidargs if opts.get(ia)]
if currentinvalidargs:
raise error.Abort(
_("--reuse-message and --%s are " "mutually exclusive")
% (currentinvalidargs[0])
)
if rev:
opts["message"] = scmutil.revsingle(repo, rev).description()
return orig(ui, repo, *pats, **opts)

View File

@ -1735,6 +1735,7 @@ def clone(ui, source, dest=None, **opts):
("s", "secret", None, _("use the secret phase for committing")),
("e", "edit", None, _("invoke editor on commit messages")),
("i", "interactive", None, _("use interactive mode")),
("M", "reuse-message", "", _("reuse commit message from REV"), _("REV")),
]
+ walkopts
+ commitopts
@ -1825,6 +1826,18 @@ def _docommit(ui, repo, *pats, **opts):
# Let --subrepos on the command line override config setting.
ui.setconfig("ui", "commitsubrepos", True, "commit")
# Allow the commit message from another commit to be reused.
reuserev = opts.get("reuse_message")
if reuserev:
incompatibleopts = ["message", "logfile"]
currentinvaliopts = [opt for opt in incompatibleopts if opts.get(opt)]
if currentinvaliopts:
raise error.Abort(
_("--reuse-message and --%s are mutually exclusive")
% (currentinvaliopts[0])
)
opts["message"] = scmutil.revsingle(repo, reuserev).description()
cmdutil.checkunfinished(repo, commit=True)
branch = repo[None].branch()

46
tests/test-commit-reuse.t Normal file
View File

@ -0,0 +1,46 @@
Test the flag to reuse another commit's message (-M):
$ newrepo
$ drawdag << 'EOS'
> B
> |
> A
> EOS
$ hg up -Cq $B
$ touch afile
$ hg add afile
$ hg commit -M $B
$ tglog
@ 2: 1c3d011e7c74 'B'
|
o 1: 112478962961 'B'
|
o 0: 426bada5c675 'A'
Ensure it's incompatible with other flags:
$ echo 'canada rocks, eh?' > afile
$ hg commit -M . -m 'this command will fail'
abort: --reuse-message and --message are mutually exclusive
[255]
$ echo 'Super duper commit message' > ../commitmessagefile
$ hg commit -M . -l ../commitmessagefile
abort: --reuse-message and --logfile are mutually exclusive
[255]
Ensure it supports nonexistant revisions:
$ hg commit -M thisrevsetdoesnotexist
abort: unknown revision 'thisrevsetdoesnotexist'!
[255]
Ensure it populates the message editor:
$ HGEDITOR=cat hg commit -M . -e
B
HG: Enter commit message. Lines beginning with 'HG:' are removed.
HG: Leave message empty to abort commit.
HG: --
HG: user: test
HG: branch 'default'
HG: changed afile

View File

@ -240,7 +240,7 @@ Show all commands + options
add: include, exclude, subrepos, dry-run
annotate: rev, follow, no-follow, text, user, file, date, number, changeset, line-number, skip, ignore-all-space, ignore-space-change, ignore-blank-lines, ignore-space-at-eol, include, exclude, template
clone: noupdate, updaterev, rev, branch, pull, uncompressed, stream, ssh, remotecmd, insecure
commit: addremove, close-branch, amend, secret, edit, interactive, include, exclude, message, logfile, date, user, subrepos
commit: addremove, close-branch, amend, secret, edit, interactive, reuse-message, include, exclude, message, logfile, date, user, subrepos
diff: rev, change, text, git, binary, nodates, noprefix, show-function, reverse, ignore-all-space, ignore-space-change, ignore-blank-lines, ignore-space-at-eol, unified, stat, root, only-files-in-revs, include, exclude, subrepos
export: output, switch-parent, rev, text, git, binary, nodates
forget: include, exclude

View File

@ -416,37 +416,6 @@ Test histedit date when tweakdefaults.histeditkeepdate is not set
18 commit 3 for histedit
17 commit 2 for histedit
Test reuse message flag by taking message from previous commit
$ cd ../..
$ hg up -q hyphen-book
$ touch afile
$ hg add afile
$ hg commit -M 2
$ hg log --template {desc} -r .
b (no-eol)
$ echo 'canada rocks, eh?' > afile
$ hg commit -M . -m 'this command will fail'
abort: --reuse-message and --message are mutually exclusive
[255]
$ echo 'Super duper commit message' > ../commitmessagefile
$ hg commit -M . -l ../commitmessagefile
abort: --reuse-message and --logfile are mutually exclusive
[255]
$ hg commit -M thisrevsetdoesnotexist
abort: unknown revision 'thisrevsetdoesnotexist'!
[255]
$ HGEDITOR=cat hg commit -M . -e
b
HG: Enter commit message. Lines beginning with 'HG:' are removed.
HG: Leave message empty to abort commit.
HG: --
HG: user: test
HG: branch 'foo'
HG: bookmark 'hyphen-book'
HG: changed afile
Test non-remotenames use of pull --rebase and --update requires --dest
$ cd $TESTTMP
$ hg clone repo clone