tags: require -f to replace an existing tag
authorMatt Mackall <mpm@selenic.com>
Fri, 23 Mar 2007 00:12:28 -0500
changeset 4267 8185a1ca8628
parent 4266 fe7f38dda34b
child 4268 f38f90a177dc
child 4304 4787e2b0dd03
tags: require -f to replace an existing tag based on a patch from Johan Herland <johherla@online.no>
mercurial/commands.py
tests/test-tags
tests/test-tags.out
--- a/mercurial/commands.py	Thu Mar 22 23:52:50 2007 -0500
+++ b/mercurial/commands.py	Fri Mar 23 00:12:28 2007 -0500
@@ -2463,6 +2463,9 @@
         rev_ = nullid
         if not message:
             message = _('Removed tag %s') % name
+    elif name in repo.tags() and not opts['force']:
+        raise util.Abort(_('a tag named %s already exists (use -f to force)')
+                         % name)
     if not rev_ and repo.dirstate.parents()[1] != nullid:
         raise util.Abort(_('uncommitted merge - please provide a '
                            'specific revision'))
@@ -2955,7 +2958,8 @@
          _('hg status [OPTION]... [FILE]...')),
     "tag":
         (tag,
-         [('l', 'local', None, _('make the tag local')),
+         [('f', 'force', None, _('replace existing tag')),
+          ('l', 'local', None, _('make the tag local')),
           ('m', 'message', '', _('message for tag commit log entry')),
           ('d', 'date', '', _('record datecode as commit date')),
           ('u', 'user', '', _('record user as commiter')),
--- a/tests/test-tags	Thu Mar 22 23:52:50 2007 -0500
+++ b/tests/test-tags	Fri Mar 23 00:12:28 2007 -0500
@@ -74,7 +74,7 @@
 echo >> foo
 hg ci -m 'change foo 1' -d '1000000 0' # rev 2
 hg up -C 1
-hg tag -r 1 -d '1000000 0' bar         # rev 3
+hg tag -r 1 -d '1000000 0' -f bar      # rev 3
 hg up -C 1
 echo >> foo
 hg ci -m 'change foo 2' -d '1000000 0' # rev 4
@@ -91,14 +91,17 @@
 cd t3
 echo foo > foo
 hg add foo
-hg ci -m 'add foo' -d '1000000 0'      # rev 0
-hg tag -d '1000000 0' bar              # rev 1 bar -> 0
-hg tag -d '1000000 0' bar              # rev 2 bar -> 1
-hg tag -d '1000000 0' -r 0 bar         # rev 3 bar -> 0
-hg tag -d '1000000 0' -r 1 bar         # rev 3 bar -> 1
-hg tag -d '1000000 0' -r 0 bar         # rev 4 bar -> 0
+hg ci -m 'add foo' -d '1000000 0'       # rev 0
+hg tag -d '1000000 0' -f bar            # rev 1 bar -> 0
+hg tag -d '1000000 0' -f bar            # rev 2 bar -> 1
+hg tag -d '1000000 0' -fr 0 bar         # rev 3 bar -> 0
+hg tag -d '1000000 0' -fr 1 bar         # rev 3 bar -> 1
+hg tag -d '1000000 0' -fr 0 bar         # rev 4 bar -> 0
 hg tags
 hg co 3
 echo barbar > foo
-hg ci -m 'change foo' -d '1000000 0'      # rev 0
+hg ci -m 'change foo' -d '1000000 0'    # rev 0
 hg tags
+
+hg tag -d '1000000 0' -r 3 bar         # should complain
+hg tags
\ No newline at end of file
--- a/tests/test-tags.out	Thu Mar 22 23:52:50 2007 -0500
+++ b/tests/test-tags.out	Fri Mar 23 00:12:28 2007 -0500
@@ -54,3 +54,6 @@
 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
 tip                                6:b5ff9d142648
 bar                                0:b409d9da318e
+abort: a tag named bar already exists (use -f to force)
+tip                                6:b5ff9d142648
+bar                                0:b409d9da318e