Patchwork D7620: merge: add commands.merge.require-rev to require an argument to hg merge

login
register
mail settings
Submitter phabricator
Date Dec. 12, 2019, 10:50 p.m.
Message ID <differential-rev-PHID-DREV-foyuyxgcrmxfzil33ipg-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/43762/
State Superseded
Headers show

Comments

phabricator - Dec. 12, 2019, 10:50 p.m.
spectral created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  This is related to commands.rebase.requiredest, commands.update.requiredest, and
  commands.push.require-revs. Since it isn't really a "destination", I went with
  require-rev to be similar to push's require-revs.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D7620

AFFECTED FILES
  mercurial/commands.py
  mercurial/configitems.py
  tests/test-merge-default.t
  tests/test-merge-tools.t

CHANGE DETAILS




To: spectral, #hg-reviewers
Cc: mercurial-devel
phabricator - Dec. 13, 2019, 8:10 a.m.
This revision now requires changes to proceed.
dlax added a comment.
dlax requested changes to this revision.


  This should be documented in `mercurial/helptext/config.txt` I think.
  
  Otherwise, this look sensible to me.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D7620/new/

REVISION DETAIL
  https://phab.mercurial-scm.org/D7620

To: spectral, #hg-reviewers, dlax
Cc: dlax, mercurial-devel
phabricator - Dec. 14, 2019, 1:38 a.m.
spectral added a comment.


  In D7620#112376 <https://phab.mercurial-scm.org/D7620#112376>, @dlax wrote:
  
  > This should be documented in `mercurial/helptext/config.txt` I think.
  
  Done.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D7620/new/

REVISION DETAIL
  https://phab.mercurial-scm.org/D7620

To: spectral, #hg-reviewers, dlax
Cc: dlax, mercurial-devel

Patch

diff --git a/tests/test-merge-tools.t b/tests/test-merge-tools.t
--- a/tests/test-merge-tools.t
+++ b/tests/test-merge-tools.t
@@ -4,6 +4,8 @@ 
   $ cat >> $HGRCPATH << EOF
   > [ui]
   > merge=
+  > [commands]
+  > merge.require-rev=True
   > EOF
   $ hg init repo
   $ cd repo
@@ -1908,6 +1910,7 @@ 
   0 files updated, 0 files merged, 0 files removed, 1 files unresolved
   use 'hg resolve' to retry unresolved file merges or 'hg merge --abort' to abandon
   [1]
+(Testing that commands.merge.require-rev doesn't break --abort)
   $ hg merge --abort -q
 
 (for ui.merge, ignored unintentionally)
diff --git a/tests/test-merge-default.t b/tests/test-merge-default.t
--- a/tests/test-merge-default.t
+++ b/tests/test-merge-default.t
@@ -44,9 +44,10 @@ 
   (run 'hg heads .' to see heads, specify rev with -r)
   [255]
 
-Should succeed:
+Should succeed (we're specifying commands.merge.require-rev=True just to test
+that it allows merge to succeed if we specify a revision):
 
-  $ hg merge 2
+  $ hg merge 2 --config commands.merge.require-rev=True
   0 files updated, 1 files merged, 0 files removed, 0 files unresolved
   (branch merge, don't forget to commit)
   $ hg id -Tjson
@@ -63,6 +64,13 @@ 
   ]
   $ hg commit -mm1
 
+Should fail because we didn't specify a revision (even though it would have
+succeeded without this):
+
+  $ hg merge --config commands.merge.require-rev=True
+  abort: configuration requires specifying revision to merge with
+  [255]
+
 Should succeed - 2 heads:
 
   $ hg merge -P
@@ -88,6 +96,13 @@ 
    }
   ]
 
+Should fail because we didn't specify a revision (even though it would have
+failed without this due to being on tip, but this check comes first):
+
+  $ hg merge --config commands.merge.require-rev=True
+  abort: configuration requires specifying revision to merge with
+  [255]
+
 Should fail because at tip:
 
   $ hg merge
diff --git a/mercurial/configitems.py b/mercurial/configitems.py
--- a/mercurial/configitems.py
+++ b/mercurial/configitems.py
@@ -228,6 +228,9 @@ 
     b'commands', b'grep.all-files', default=False, experimental=True,
 )
 coreconfigitem(
+    b'commands', b'merge.require-rev', default=False,
+)
+coreconfigitem(
     b'commands', b'push.require-revs', default=False,
 )
 coreconfigitem(
diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -4888,6 +4888,13 @@ 
         node = scmutil.revsingle(repo, node).node()
 
     if not node and not abort:
+        if ui.configbool(b'commands', b'merge.require-rev'):
+            raise error.Abort(
+                _(
+                    b'configuration requires specifying revision to merge '
+                    b'with'
+                )
+            )
         node = repo[destutil.destmerge(repo)].node()
 
     if opts.get(b'preview'):