changeset 11063:eb23c876c111

tag: warn users about tag/branch possible name conflicts As reported recently, Mercurial users can easily find confusion when using a common name for a tag and a branch. It seems reasonable to warn them about this potential outcome, to avoid that "surprise". * Explain briefly the issue in "hg help tag" * Warn when tagging a revision
author Nicolas Dumazet <nicdumz.commits@gmail.com>
date Mon, 19 Apr 2010 17:41:12 +0900
parents a2a6fd1064df
children 590b1d6ef50b
files mercurial/commands.py mercurial/localrepo.py tests/test-tag tests/test-tag.out
diffstat 4 files changed, 15 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/commands.py	Mon Apr 19 11:31:19 2010 +0200
+++ b/mercurial/commands.py	Mon Apr 19 17:41:12 2010 +0900
@@ -3209,6 +3209,9 @@
     shared among repositories).
 
     See :hg:`help dates` for a list of formats valid for -d/--date.
+
+    Since tag names have priority over branch names during revision
+    lookup, using an existing branch name as a tag name is discouraged.
     """
 
     rev_ = "."
--- a/mercurial/localrepo.py	Mon Apr 19 11:31:19 2010 +0200
+++ b/mercurial/localrepo.py	Mon Apr 19 17:41:12 2010 +0900
@@ -164,9 +164,13 @@
             if c in allchars:
                 raise util.Abort(_('%r cannot be used in a tag name') % c)
 
+        branches = self.branchmap()
         for name in names:
             self.hook('pretag', throw=True, node=hex(node), tag=name,
                       local=local)
+            if name in branches:
+                self.ui.warn(_("warning: tag %s conflicts with existing"
+                " branch name\n") % name)
 
         def writetags(fp, names, munge, prevtags):
             fp.seek(0, 2)
--- a/tests/test-tag	Mon Apr 19 11:31:19 2010 +0200
+++ b/tests/test-tag	Mon Apr 19 17:41:12 2010 +0900
@@ -68,3 +68,8 @@
 cat .hgtags
 hg tag -d '1000000 0' newline
 cat .hgtags
+
+echo % tag and branch using same name
+hg branch tag-and-branch-same-name
+hg ci -m"discouraged"
+hg tag tag-and-branch-same-name
--- a/tests/test-tag.out	Mon Apr 19 11:31:19 2010 +0200
+++ b/tests/test-tag.out	Mon Apr 19 17:41:12 2010 +0900
@@ -94,3 +94,6 @@
 f68b039e72eacbb2e68b0543e1f6e50990aa2bb5 localnewline
 0acdaf8983679e0aac16e811534eb49d7ee1f2b4 foobar0acdaf8983679e0aac16e811534eb49d7ee1f2b4 foobar
 6ae703d793c8b1f097116869275ecd97b2977a2b newline
+% tag and branch using same name
+marked working directory as branch tag-and-branch-same-name
+warning: tag tag-and-branch-same-name conflicts with existing branch name