[PATCH] tag: warn users about tag/branch possible name conflicts

Dirkjan Ochtman dirkjan at ochtman.nl
Mon Apr 19 04:04:54 CDT 2010


On Mon, Apr 19, 2010 at 10:51, Nicolas Dumazet <nicdumz at gmail.com> wrote:
> # HG changeset patch
> # User Nicolas Dumazet <nicdumz.commits at gmail.com>
> # Date 1271666472 -32400
> # Node ID 6359fa7f71f1000ecb912805f8f3ab963600908b
> # Parent  97fa807d0f6738bc0cb6f834582b48697575e550
> 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

Nice one.

>
> diff --git a/mercurial/commands.py b/mercurial/commands.py
> --- a/mercurial/commands.py
> +++ b/mercurial/commands.py
> @@ -3207,6 +3207,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_ = "."
> diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
> --- a/mercurial/localrepo.py
> +++ b/mercurial/localrepo.py
> @@ -164,9 +164,13 @@
>             if c in allchars:
>                 raise util.Abort(_('%r cannot be used in a tag name') % c)
>
> +        branches = self.branchtags()
>         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 can conflict with existing"
> +                " branch name\n") % name)

Nit: I think "can conflict" should either be "conflicts" (my
preference) or maybe "may conflict".

>         def writetags(fp, names, munge, prevtags):
>             fp.seek(0, 2)
> diff --git a/tests/test-tag b/tests/test-tag
> --- a/tests/test-tag
> +++ b/tests/test-tag
> @@ -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
> diff --git a/tests/test-tag.out b/tests/test-tag.out
> --- a/tests/test-tag.out
> +++ b/tests/test-tag.out
> @@ -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 can conflict with existing branch name
>


More information about the Mercurial-devel mailing list