changeset 13136:6320101a638c

merge with stable
author Matt Mackall <mpm@selenic.com>
date Tue, 14 Dec 2010 17:10:01 -0600
parents 24e3349cba8e (current diff) 1c1ca9d393f4 (diff)
children 7397a53219c9
files mercurial/commands.py mercurial/localrepo.py
diffstat 4 files changed, 108 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/commands.py	Thu Dec 09 17:33:40 2010 -0600
+++ b/mercurial/commands.py	Tue Dec 14 17:10:01 2010 -0600
@@ -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.
 
@@ -3717,9 +3724,13 @@
             if n in repo.tags():
                 raise util.Abort(_('tag \'%s\' already exists '
                                    '(use -f to force)') % n)
-    if not rev_ and repo.dirstate.parents()[1] != nullid:
-        raise util.Abort(_('uncommitted merge - please provide a '
-                           'specific revision'))
+    if not opts.get('local'):
+        p1, p2 = repo.dirstate.parents()
+        if p2 != nullid:
+            raise util.Abort(_('uncommitted merge'))
+        bheads = repo.branchheads()
+        if not opts.get('force') and bheads and p1 not in bheads:
+            raise util.Abort(_('not at a branch head (use -f to force)'))
     r = cmdutil.revsingle(repo, rev_).node()
 
     if not message:
@@ -4481,7 +4492,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')),
--- a/mercurial/localrepo.py	Thu Dec 09 17:33:40 2010 -0600
+++ b/mercurial/localrepo.py	Tue Dec 14 17:10:01 2010 -0600
@@ -308,10 +308,11 @@
 
         date: date tuple to use if committing'''
 
-        for x in self.status()[:5]:
-            if '.hgtags' in x:
-                raise util.Abort(_('working copy of .hgtags is changed '
-                                   '(please commit .hgtags manually)'))
+        if not local:
+            for x in self.status()[:5]:
+                if '.hgtags' in x:
+                    raise util.Abort(_('working copy of .hgtags is changed '
+                                       '(please commit .hgtags manually)'))
 
         self.tags() # instantiate the cache
         self._tag(names, node, message, local, user, date)
--- a/tests/test-1102.t	Thu Dec 09 17:33:40 2010 -0600
+++ b/tests/test-1102.t	Tue Dec 14 17:10:01 2010 -0600
@@ -9,7 +9,7 @@
 
   $ hg co 1
   1 files updated, 0 files merged, 0 files removed, 0 files unresolved
-  $ hg tag -r0 t1
+  $ hg tag -f -r0 t1
   $ hg tags
   tip                                3:a49829c4fc11
   t1                                 0:f7b1eb17ad24
--- a/tests/test-tag.t	Thu Dec 09 17:33:40 2010 -0600
+++ b/tests/test-tag.t	Tue Dec 14 17:10:01 2010 -0600
@@ -78,13 +78,20 @@
   $ cat .hg/localtags
   d4f0d2909abc9290e2773c08837d70c1794e3f5a bleah1
 
+tagging on a non-head revision
+
   $ hg update 0
   0 files updated, 0 files merged, 1 files removed, 0 files unresolved
+  $ hg tag -l localblah
   $ 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
   d4f0d2909abc9290e2773c08837d70c1794e3f5a bleah1
+  acb14030fe0a21b60322c440ad2d20cf7685a376 localblah
 
   $ hg tag -l 'xx
   > newline'
@@ -102,6 +109,7 @@
   tag:         bleah
   tag:         bleah0
   tag:         foobar
+  tag:         localblah
   user:        test
   date:        Thu Jan 01 00:00:00 1970 +0000
   summary:     test
@@ -156,10 +164,10 @@
   > f = file('.hg/localtags', 'w'); f.write(last); f.close()
   > EOF
   $ cat .hg/localtags; echo
-  d4f0d2909abc9290e2773c08837d70c1794e3f5a bleah1
+  acb14030fe0a21b60322c440ad2d20cf7685a376 localblah
   $ hg tag -l localnewline
   $ cat .hg/localtags; echo
-  d4f0d2909abc9290e2773c08837d70c1794e3f5a bleah1
+  acb14030fe0a21b60322c440ad2d20cf7685a376 localblah
   c2899151f4e76890c602a2597a650a72666681bf localnewline
   
 
@@ -196,3 +204,75 @@
   $ hg log -l1 --template "{desc}\n"
   custom tag message
   second line
+
+
+local tag with .hgtags modified
+
+  $ hg tag hgtags-modified
+  $ hg rollback
+  rolling back to revision 11 (undo commit)
+  $ hg st
+  M .hgtags
+  ? .hgtags.orig
+  ? editor
+  $ hg tag --local baz
+  $ hg revert --no-backup .hgtags
+
+
+tagging when at named-branch-head that's not a topo-head
+
+  $ 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
+
+
+tagging on null rev
+
+  $ hg up null
+  0 files updated, 0 files merged, 2 files removed, 0 files unresolved
+  $ hg tag nullrev
+  abort: not at a branch head (use -f to force)
+  [255]
+
+  $ hg init empty
+  $ hg tag -R empty nullrev
+
+  $ cd ..
+
+tagging on an uncommitted merge (issue2542)
+
+  $ hg init repo-tag-uncommitted-merge
+  $ cd repo-tag-uncommitted-merge
+  $ echo c1 > f1
+  $ hg ci -Am0
+  adding f1
+  $ hg branch b1
+  marked working directory as branch b1
+  $ echo c2 >> f1
+  $ hg ci -m1
+  $ hg up default
+  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  $ hg merge b1
+  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  (branch merge, don't forget to commit)
+
+  $ hg tag t1
+  abort: uncommitted merge
+  [255]
+  $ hg status
+  M f1
+  $ hg tag --rev 1 t2
+  abort: uncommitted merge
+  [255]
+  $ hg tag --rev 1 --local t3
+  $ hg tags -v
+  tip                                1:9466ada9ee90
+  t3                                 1:9466ada9ee90 local
+
+  $ cd ..