[PATCH 1 of 1 RFC] tag: abort if not at a branch head

Kevin Bullock kbullock+mercurial at ringworld.org
Mon Dec 6 13:56:19 CST 2010


# HG changeset patch
# User Kevin Bullock <kbullock at ringworld.org>
# Date 1291665075 21600
# Node ID f52e752c6d5f90352bb29ba6c2543656f6e4531e
# Parent  8c6b7a5f38c4585b1b2c2ceaffa8023f36a18479
tag: abort if not at a branch head

Since it's usually only desirable to make tag commits on top of branch
heads, abort if the working dir parent is not a branch head. -f/--force
may be passed to commit at a non-head anyway.

Does not abort if working dir parent is a named branch head but not a
topological head.

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -3665,16 +3665,23 @@
 
     Tags are used to name particular revisions of the repository and are
     very useful to compare different revisions, to go back to significant
-    earlier versions or to mark branch points as releases, etc.
+    earlier versions or to mark branch points as releases, etc. Changing
+    an existing tag is normally disallowed; use -f/--force to override.
 
     If no revision is given, the parent of the working directory is
     used, or tip if no revision is checked out.
 
     To facilitate version control, distribution, and merging of tags,
-    they are stored as a file named ".hgtags" which is managed
-    similarly to other project files and can be hand-edited if
-    necessary. The file '.hg/localtags' is used for local tags (not
-    shared among repositories).
+    they are stored as a file named ".hgtags" which is managed similarly
+    to other project files and can be hand-edited if necessary. This
+    also means that tagging creates a new commit. The file
+    ".hg/localtags" is used for local tags (not shared among
+    repositories).
+
+    Tag commits are usually made at the head of a branch. If the parent
+    of the working directory is not a branch head, :hg:`tag` aborts; use
+    -f/--force to force the tag commit to be based on a non-head
+    changeset.
 
     See :hg:`help dates` for a list of formats valid for -d/--date.
 
@@ -3713,6 +3720,11 @@
             # we don't translate commit messages
             message = 'Removed tag %s' % ', '.join(names)
     elif not opts.get('force'):
+        wctx = repo[None]
+        bheads = repo.branchheads()
+        if bheads and not [x for x in wctx.parents()
+                           if x.node() in bheads]:
+            raise util.Abort(_('not at a branch head (use -f to force)'))
         for n in names:
             if n in repo.tags():
                 raise util.Abort(_('tag \'%s\' already exists '
@@ -4481,7 +4493,7 @@
          _('[OPTION]... [FILE]...')),
     "tag":
         (tag,
-         [('f', 'force', None, _('replace existing tag')),
+         [('f', 'force', None, _('force tag')),
           ('l', 'local', None, _('make the tag local')),
           ('r', 'rev', '',
            _('revision to tag'), _('REV')),
diff --git a/tests/test-tag.t b/tests/test-tag.t
--- a/tests/test-tag.t
+++ b/tests/test-tag.t
@@ -81,6 +81,9 @@
   $ hg update 0
   0 files updated, 0 files merged, 1 files removed, 0 files unresolved
   $ hg tag "foobar"
+  abort: not at a branch head (use -f to force)
+  [255]
+  $ hg tag -f "foobar"
   $ cat .hgtags
   acb14030fe0a21b60322c440ad2d20cf7685a376 foobar
   $ cat .hg/localtags
@@ -196,3 +199,18 @@
   $ hg log -l1 --template "{desc}\n"
   custom tag message
   second line
+
+
+tagging when at named-branch-head that's not a topo-head
+
+  $ hg parents -q
+  11:7d32ded1f932
+  $ hg up default
+  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  $ hg merge -t internal:local
+  0 files updated, 1 files merged, 0 files removed, 0 files unresolved
+  (branch merge, don't forget to commit)
+  $ hg ci -m 'merge named branch'
+  $ hg up 11
+  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  $ hg tag new-topo-head


More information about the Mercurial-devel mailing list