Patchwork [2,of,4,V2] commit: add ui.allowemptycommit config option

login
register
mail settings
Submitter Durham Goode
Date May 12, 2015, 3:29 a.m.
Message ID <37ef345236b146ffc75a.1431401351@dev2000.prn2.facebook.com>
Download mbox | patch
Permalink /patch/9025/
State Accepted
Headers show

Comments

Durham Goode - May 12, 2015, 3:29 a.m.
# HG changeset patch
# User Durham Goode <durham@fb.com>
# Date 1431386308 25200
#      Mon May 11 16:18:28 2015 -0700
# Node ID 37ef345236b146ffc75a6414411ffb6bea870a74
# Parent  bb446b7270951339396e948f4e4474781d830eff
commit: add ui.allowemptycommit config option

This adds a config flag that enables a user to make empty commits.
This is useful in a number of cases.

For instance, automation that creates release branches via
bookmarks may want to make empty commits to that release bookmark so that it
can't be fast forwarded and so it can record information about the release
bookmark's creation. This is already possible with named branches, so making it
possible for bookmarks makes sense.

Another case we've wanted it is for mirroring repositories into Mercurial. We
have automation that syncs commits into hg by running things from the command
line. The ability to produce empty commits is useful for syncing unusual commits
from other VCS's.

In general, allowing the user to create the DAG as they see fit seems useful,
and when I mentioned this in IRC more than one person piped up and said they
were already hacking around this limitation by using mq, import, and
commit-dummy-change-then-amend-the-content-away style solutions.
Jordi GutiƩrrez Hermoso - May 13, 2015, 12:15 a.m.
On Mon, 2015-05-11 at 20:29 -0700, Durham Goode wrote:
> # HG changeset patch
> # User Durham Goode <durham@fb.com>
> # Date 1431386308 25200
> #      Mon May 11 16:18:28 2015 -0700
> # Node ID 37ef345236b146ffc75a6414411ffb6bea870a74
> # Parent  bb446b7270951339396e948f4e4474781d830eff
> commit: add ui.allowemptycommit config option
> 
> This adds a config flag that enables a user to make empty commits.
> This is useful in a number of cases.
> 
> For instance, automation that creates release branches via
> bookmarks may want to make empty commits to that release bookmark so that it
> can't be fast forwarded

Can we please say "advanced" here instead? "Fast forwarding" from git
lacks certain connotations such as consolidating divergent bookmarks,
and brings others such as the idea that moving bookmarks has something
to do with merges. As someone who routinely uses commit messages as
API documentation, I advocate for clarity.

Other than this linguistic quibble, this series seems to me to be in pretty
good shape.

Patch

diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -1463,7 +1463,8 @@  class localrepository(object):
                                             text, user, date, extra)
 
             allowemptycommit = (wctx.branch() != wctx.p1().branch() or force
-                                or extra.get('close') or merge or cctx.files())
+                                or extra.get('close') or merge or cctx.files()
+                                or self.ui.configbool('ui', 'allowemptycommit'))
             if not allowemptycommit:
                 return None
 
diff --git a/tests/test-commit.t b/tests/test-commit.t
--- a/tests/test-commit.t
+++ b/tests/test-commit.t
@@ -544,6 +544,18 @@  commit copy
        0         0       6  .....       0 26d3ca0dfd18 000000000000 000000000000 (re)
        1         6       7  .....       1 d267bddd54f7 26d3ca0dfd18 000000000000 (re)
 
+Test making empty commits
+  $ hg commit --config ui.allowemptycommit=True -m "empty commit"
+  $ hg log -r . -v --stat
+  changeset:   2:d809f3644287
+  tag:         tip
+  user:        test
+  date:        Thu Jan 01 00:00:00 1970 +0000
+  description:
+  empty commit
+  
+  
+  
 verify pathauditor blocks evil filepaths
   $ cat > evil-commit.py <<EOF
   > from mercurial import ui, hg, context, node
@@ -568,7 +580,7 @@  verify pathauditor blocks evil filepaths
 #endif
 
   $ hg rollback -f
-  repository tip rolled back to revision 1 (undo commit)
+  repository tip rolled back to revision 2 (undo commit)
   $ cat > evil-commit.py <<EOF
   > from mercurial import ui, hg, context, node
   > notrc = "HG~1/hgrc"
@@ -586,7 +598,7 @@  verify pathauditor blocks evil filepaths
   [255]
 
   $ hg rollback -f
-  repository tip rolled back to revision 1 (undo commit)
+  repository tip rolled back to revision 2 (undo commit)
   $ cat > evil-commit.py <<EOF
   > from mercurial import ui, hg, context, node
   > notrc = "HG8B6C~2/hgrc"