Patchwork D2862: uncommit: leave empty commit if all files are uncommitted

login
register
mail settings
Submitter phabricator
Date March 14, 2018, 6:21 p.m.
Message ID <differential-rev-PHID-DREV-jrr7ntjgbsmbhxd5jjcy-req@phab.mercurial-scm.org>
Download mbox | patch
Permalink /patch/29508/
State Superseded
Headers show

Comments

phabricator - March 14, 2018, 6:21 p.m.
martinvonz created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  We had instructions for our internal users to add copy information
  after commit like this:
  
    hg uncommit <srcfile> <dstfile>
    hg cp --after <srcfile> <dstfile>
    hg amend
  
  That usually works, but if the rename was the only change in that
  commit, then the commit would get pruned. It's easy to fix the recipe:
  just pass the --keep option. However, it seems too subtle, so I think
  this is an indication that the commit should not be pruned if any
  patterns were given.

REPOSITORY
  rHG Mercurial

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

AFFECTED FILES
  hgext/uncommit.py
  tests/test-uncommit.t

CHANGE DETAILS




To: martinvonz, #hg-reviewers
Cc: mercurial-devel
phabricator - March 17, 2018, 11:45 a.m.
pulkit added a comment.


  Queuing this many thanks. Can you please send a followup with documenting the behavior of command related to pruning the empty changeset?

REPOSITORY
  rHG Mercurial

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

To: martinvonz, #hg-reviewers, durham, ryanmce
Cc: pulkit, mercurial-devel

Patch

diff --git a/tests/test-uncommit.t b/tests/test-uncommit.t
--- a/tests/test-uncommit.t
+++ b/tests/test-uncommit.t
@@ -158,7 +158,7 @@ 
   $ cat files
   abcde
   foo
-  $ hg commit -m "files abcde + foo"
+  $ hg commit --amend -m "files abcde + foo"
 
 Testing the 'experimental.uncommitondirtywdir' config
 
@@ -188,16 +188,16 @@ 
   +abc
   
   $ hg bookmark
-     foo                       9:48e5bd7cd583
+     foo                       10:48e5bd7cd583
   $ hg uncommit
   3 new orphan changesets
   $ hg status
   M files
   A file-abc
   $ hg heads -T '{rev}:{node} {desc}'
-  9:48e5bd7cd583eb24164ef8b89185819c84c96ed7 files abcde + foo (no-eol)
+  10:48e5bd7cd583eb24164ef8b89185819c84c96ed7 files abcde + foo (no-eol)
   $ hg bookmark
-     foo                       9:48e5bd7cd583
+     foo                       10:48e5bd7cd583
   $ hg commit -m 'new abc'
   created new head
 
@@ -219,36 +219,38 @@ 
   +ab
   
   $ hg bookmark
-     foo                       9:48e5bd7cd583
+     foo                       10:48e5bd7cd583
   $ hg uncommit file-ab
   1 new orphan changesets
   $ hg status
   A file-ab
 
   $ hg heads -T '{rev}:{node} {desc}\n'
-  11:8eb87968f2edb7f27f27fe676316e179de65fff6 added file-ab
-  10:5dc89ca4486f8a88716c5797fa9f498d13d7c2e1 new abc
-  9:48e5bd7cd583eb24164ef8b89185819c84c96ed7 files abcde + foo
+  12:8eb87968f2edb7f27f27fe676316e179de65fff6 added file-ab
+  11:5dc89ca4486f8a88716c5797fa9f498d13d7c2e1 new abc
+  10:48e5bd7cd583eb24164ef8b89185819c84c96ed7 files abcde + foo
 
   $ hg bookmark
-     foo                       9:48e5bd7cd583
+     foo                       10:48e5bd7cd583
   $ hg commit -m 'update ab'
   $ hg status
   $ hg heads -T '{rev}:{node} {desc}\n'
-  12:f21039c59242b085491bb58f591afc4ed1c04c09 update ab
-  10:5dc89ca4486f8a88716c5797fa9f498d13d7c2e1 new abc
-  9:48e5bd7cd583eb24164ef8b89185819c84c96ed7 files abcde + foo
+  13:f21039c59242b085491bb58f591afc4ed1c04c09 update ab
+  11:5dc89ca4486f8a88716c5797fa9f498d13d7c2e1 new abc
+  10:48e5bd7cd583eb24164ef8b89185819c84c96ed7 files abcde + foo
 
   $ hg log -G -T '{rev}:{node} {desc}' --hidden
-  @  12:f21039c59242b085491bb58f591afc4ed1c04c09 update ab
+  @  13:f21039c59242b085491bb58f591afc4ed1c04c09 update ab
   |
-  o  11:8eb87968f2edb7f27f27fe676316e179de65fff6 added file-ab
+  o  12:8eb87968f2edb7f27f27fe676316e179de65fff6 added file-ab
   |
-  | *  10:5dc89ca4486f8a88716c5797fa9f498d13d7c2e1 new abc
+  | *  11:5dc89ca4486f8a88716c5797fa9f498d13d7c2e1 new abc
   | |
-  | | *  9:48e5bd7cd583eb24164ef8b89185819c84c96ed7 files abcde + foo
+  | | *  10:48e5bd7cd583eb24164ef8b89185819c84c96ed7 files abcde + foo
   | | |
-  | | | x  8:83815831694b1271e9f207cb1b79b2b19275edcb files abcde + foo
+  | | | x  9:8a6b58c173ca6a2e3745d8bd86698718d664bc6c files abcde + foo
+  | | |/
+  | | | x  8:39ad452c7f684a55d161c574340c5766c4569278 update files for abcde
   | | |/
   | | | x  7:0977fa602c2fd7d8427ed4e7ee15ea13b84c9173 update files for abcde
   | | |/
@@ -270,15 +272,15 @@ 
 
   $ hg uncommit
   $ hg phase -r .
-  11: draft
+  12: draft
   $ hg commit -m 'update ab again'
 
 Uncommit with public parent
 
   $ hg phase -p "::.^"
   $ hg uncommit
   $ hg phase -r .
-  11: public
+  12: public
 
 Partial uncommit with public parent
 
@@ -289,9 +291,9 @@ 
   $ hg status
   A xyz
   $ hg phase -r .
-  15: draft
+  16: draft
   $ hg phase -r ".^"
-  11: public
+  12: public
 
 Uncommit leaving an empty changeset
 
diff --git a/hgext/uncommit.py b/hgext/uncommit.py
--- a/hgext/uncommit.py
+++ b/hgext/uncommit.py
@@ -166,7 +166,8 @@ 
 
         with repo.transaction('uncommit'):
             match = scmutil.match(old, pats, opts)
-            newid = _commitfiltered(repo, old, match, opts.get('keep'))
+            allowempty = opts.get('keep') or pats
+            newid = _commitfiltered(repo, old, match, allowempty)
             if newid is None:
                 ui.status(_("nothing to uncommit\n"))
                 return 1