From patchwork Sat May 10 16:08:48 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [13, of, 19] import: use "getcommiteditor()" instead of explicit editor choice From: Katsunori FUJIWARA X-Patchwork-Id: 4716 Message-Id: <76ac94ee25a1f40f12ac.1399738128@feefifofum> To: mercurial-devel@selenic.com Date: Sun, 11 May 2014 01:08:48 +0900 # HG changeset patch # User FUJIWARA Katsunori # Date 1399736976 -32400 # Sun May 11 00:49:36 2014 +0900 # Node ID 76ac94ee25a1f40f12acaf4b6f0677439a918dac # Parent bb46de5606a252cd958443ca590fd26b61fd3c90 import: use "getcommiteditor()" instead of explicit editor choice This patch also enhances "test-import-bypass.t" and "test-import.t", because "hg import" hasn't been explicitly tested around editor invocation and "--edit" option. This patch explicitly tests below: - with "--bypass" (regardless of "--edit"): - not invoked, if the patch contains the commit message - not invoked, if the commit message is explicitly specified - invoked, otherwise (just adding comment) - without "--bypass": - with "--edit": - not invoked, if "--no-commit" is not specified - invoked, otherwise - without "--edit": - not invoked, if the patch contains the commit message - not invoked, if "--message" or "--logfile" is specified (just adding comment) - invoked, otherwise diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py --- a/mercurial/cmdutil.py +++ b/mercurial/cmdutil.py @@ -569,9 +569,7 @@ tmpname, message, user, date, branch, nodeid, p1, p2 = \ patch.extract(ui, hunk) - editor = commiteditor - if opts.get('edit'): - editor = commitforceeditor + editor = getcommiteditor(**opts) update = not opts.get('bypass') strip = opts["strip"] sim = float(opts.get('similarity') or 0) @@ -660,7 +658,7 @@ opts.get('user') or user, opts.get('date') or date, branch, files, store, - editor=commiteditor) + editor=getcommiteditor()) n = memctx.commit() finally: store.close() diff --git a/tests/test-import-bypass.t b/tests/test-import-bypass.t --- a/tests/test-import-bypass.t +++ b/tests/test-import-bypass.t @@ -22,8 +22,10 @@ 0 files updated, 0 files merged, 1 files removed, 0 files unresolved Test importing an existing revision - - $ hg import --bypass --exact ../test.diff +(this also tests that editor is not invoked for '--bypass', if the +patch contains the commit message, regardless of '--edit') + + $ HGEDITOR=cat hg import --bypass --exact --edit ../test.diff applying ../test.diff $ shortlog o 1:4e322f7ce8e3 test 0 0 - foo - changea @@ -107,6 +109,8 @@ [255] Test commit editor +(this also tests that editor is invoked, if the patch doesn't contain +the commit message, regardless of '--edit') $ cat > ../test.diff < diff -r 07f494440405 -r 4e322f7ce8e3 a @@ -131,10 +135,12 @@ [255] Test patch.eol is handled +(this also tests that editor is not invoked for '--bypass', if the +commit message is explicitly specified, regardless of '--edit') $ python -c 'file("a", "wb").write("a\r\n")' $ hg ci -m makeacrlf - $ hg import -m 'should fail because of eol' --bypass ../test.diff + $ HGEDITOR=cat hg import -m 'should fail because of eol' --edit --bypass ../test.diff applying ../test.diff patching file a Hunk #1 FAILED at 0 diff --git a/tests/test-import.t b/tests/test-import.t --- a/tests/test-import.t +++ b/tests/test-import.t @@ -23,15 +23,17 @@ import exported patch - - $ hg clone -r0 a b - adding changesets - adding manifests - adding file changes - added 1 changesets with 2 changes to 2 files - updating to branch default - 2 files updated, 0 files merged, 0 files removed, 0 files unresolved - $ hg --cwd b import ../exported-tip.patch +(this also tests that editor is not invoked, if the patch contains the +commit message and '--edit' is not specified) + + $ hg clone -r0 a b + adding changesets + adding manifests + adding file changes + added 1 changesets with 2 changes to 2 files + updating to branch default + 2 files updated, 0 files merged, 0 files removed, 0 files unresolved + $ HGEDITOR=cat hg --cwd b import ../exported-tip.patch applying ../exported-tip.patch message and committer and date should be same @@ -47,6 +49,8 @@ import exported patch with external patcher +(this also tests that editor is invoked, if the '--edit' is specified, +regardless of the commit message in the patch) $ cat > dummypatch.py < print 'patching file a' @@ -59,24 +63,43 @@ added 1 changesets with 2 changes to 2 files updating to branch default 2 files updated, 0 files merged, 0 files removed, 0 files unresolved - $ hg --config ui.patch='python ../dummypatch.py' --cwd b import ../exported-tip.patch + $ HGEDITOR=cat hg --config ui.patch='python ../dummypatch.py' --cwd b import --edit ../exported-tip.patch applying ../exported-tip.patch + second change + + + HG: Enter commit message. Lines beginning with 'HG:' are removed. + HG: Leave message empty to abort commit. + HG: -- + HG: user: someone + HG: branch 'default' + HG: changed a $ cat b/a line2 $ rm -r b import of plain diff should fail without message - - $ hg clone -r0 a b - adding changesets - adding manifests - adding file changes - added 1 changesets with 2 changes to 2 files - updating to branch default - 2 files updated, 0 files merged, 0 files removed, 0 files unresolved - $ hg --cwd b import ../diffed-tip.patch +(this also tests that editor is invoked, if the patch doesn't contain +the commit message, regardless of '--edit') + + $ hg clone -r0 a b + adding changesets + adding manifests + adding file changes + added 1 changesets with 2 changes to 2 files + updating to branch default + 2 files updated, 0 files merged, 0 files removed, 0 files unresolved + $ HGEDITOR=cat hg --cwd b import ../diffed-tip.patch applying ../diffed-tip.patch + + + 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 a abort: empty commit message [255] $ rm -r b @@ -97,6 +120,8 @@ import of plain diff with specific date and user +(this also tests that editor is not invoked, if +'--message'/'--logfile' is specified and '--edit' is not) $ hg clone -r0 a b adding changesets @@ -128,15 +153,17 @@ import of plain diff should be ok with --no-commit - - $ hg clone -r0 a b - adding changesets - adding manifests - adding file changes - added 1 changesets with 2 changes to 2 files - updating to branch default - 2 files updated, 0 files merged, 0 files removed, 0 files unresolved - $ hg --cwd b import --no-commit ../diffed-tip.patch +(this also tests that editor is not invoked, if '--no-commit' is +specified, regardless of '--edit') + + $ hg clone -r0 a b + adding changesets + adding manifests + adding file changes + added 1 changesets with 2 changes to 2 files + updating to branch default + 2 files updated, 0 files merged, 0 files removed, 0 files unresolved + $ HGEDITOR=cat hg --cwd b import --no-commit --edit ../diffed-tip.patch applying ../diffed-tip.patch $ hg --cwd b diff --nodates diff -r 80971e65b431 a