Delete local tag fails - mercurial

I'm trying to delete a local tag in a Mercurial repo using:
hg tag --remove tag-name
and I get the following message:
abort: tag 'last-working' is not a global tag
Is there a way to delete local tags?

Sure:
hg tag --remove --local tag-name

Related

Conflict when try to delete Mercurial tag

I have stable tag in my Mercurial repository, and I was able to tag new stable releases of code, and everything worked perfect.
But we decided to have stable branch, which will contain only stable code, and I created this branch, but now I have problem to switch to Hg "stable" branch and not to Hg "stable" tag.
Therefore, because stable tags will not be used anymore, I thought to delete those tags using command:
hg tag --remove stable
But I got warning:
hg tag --remove stable
warning: tag stable conflicts with existing branch name
.hgtags
How can I resolve this weird problem? Is it reccomanded to manually edit .hgtags file?
Thanks!
You can manually edit the .hgtags file. It's just another file in the repository. If you screw it up you can just re-edit it and re-commit it.

How can I commit a file before the tag is committed?

I want to automatically bump the version of my project when I use hg tag XXX.
I have set up a pretag hook in my hgrc (note: I have removed the stuff that ensures it is outputting to VERSION in hg root, for clarity):
[hooks]
pretag.bump_version = (echo "$HG_TAG" > VERSION; hg commit -m "Updated VERSION to $HG_TAG" VERSION)
When I create a new tag:
$ hg tag 1.1
I get the error:
warning: ignoring unknown working parent <revision_id>!
I can use a tag hook instead, which succeeds, but then the VERSION number is exactly one revision later than the tag: which means that updating to the tagged revision, and then building will result in the product's version number (which depends upon the VERSION file) will be incorrect.
Is there a better way to handle this? I've looked at SO question #2558531, but that deals with updating the version number each time: I just want to update the version number before I tag the repository.
Switch to a pre-tag instead of a pretag hook. The hook pretag is a special hook which is aware that you're tagging. By contrast the pre-tag hook is a generic pre-* hook which is run before the tag command launches at all and is completely unaware that it's tagging -- which means it runs earlier too. (There are pre-* hooks for everything even, say, pre-log).
I got your example to work like this:
[hooks]
pre-tag.bump_version = echo $HG_ARGS > VERSION; hg commit -m "updated version to $HG_ARGS" VERSION
Using the command line only that looked like:
ry4an#ry4an:~$ hg init tagtest
ry4an#ry4an:~$ cd tagtest
ry4an#ry4an:~/tagtest$ echo text > VERSION
ry4an#ry4an:~/tagtest$ hg commit -A -m initial
adding file
ry4an#ry4an:~/tagtest$ hg tag --config hooks.pre-tag='echo $HG_ARGS > VERSION; hg commit -m "updated version to $HG_ARGS" VERSION' 1.1
Notice I had to switch the argument to $HG_ARGS since it's a pre-* command that doesn't know we're tagging. The details are in the hgrc manpage.
Also note I'm committing only the VERSION file when I commit in the hook by naming it explicitly. You don't want to accidentally commit a bunch of debugging stuff you'd excluded from a previous commit just because you tagged.

Mercurial hooks -- pass information between hooks?

I currently have a pre-commit hook in my mercurial project that gives the user the option to update the version number of the project if they wish (e.g. 1.0 to 1.0.1 or 1.1 or 2.0). They select one of these options, and the hook updates the version number in one of the project's files prior to the commit taking place.
When I run hg commit, this hook runs and updates the relevant file with the new version number, and then performs the commit.
I'd like to add to the hook such that it calls hg tag <new_verson_number> as well.
However, I can't add this to the pre-commit hook, because then the tag will be added before the commit is called, causing the tag to be one revision out of date.
I'd like to add the hg tag command to a commit hook (run after the commit), so that the sequence of events is like so:
hg commit -m "my commit message"
user says yes, I'd like to change the version number
version number is updated in the relevant file
commit occurs [everything up to here is fine]
if the user changed the version number, run a commit hook: hg tag <new_version_number>.
Now, I could add a commit hook that read off the new version number from the file it's stored in and run hg tag <new_version_number>, but what if the user decided not to change the version number? In that case, I don't want a tag added, and if I blindly run hg tag <new_version_number> I'll end up with tags I don't want.
So - is there some way I can tell the pre-commit hook to leave some information for the commit hook (a yes/no of whether to add the tag), and the commit hook can use this to determine whether to add the tag or not?
cheers.
How about a commit hook that checks if the last commit modified the file in which you store the version? Something like:
[hooks]
commit.tagversion = if hg log -r $HG_NODE --template '{files}' | grep -q VERSION_FILE ; then hg tag $(hg cat -r $HG_NODE VERSION_FILE) ; fi
I haven't tested it, but that or something like it should work.
You could extract the tag name that you would add and then check to see if it already exists in hg tags before you add it. That would also catch the case where the developer amends the version number manually.

Tagging a subrepository only

I have a Mercurial main-repository with one sub-repository, like this:
Main
.hg
.hgsub
.hgsubstate
<some_regular_files_and_subdirs>
Sub
.hg
<some_regular_files_and_subdirs>
And I wish to tag Sub, only, while keeping Main/.hgsubstate up-to-date (i.e. point to the changeset of Sub resulting from the tagging process).
I don't want to tag the main-repository.
Is that possible without tagging from within Sub and do some magic to get Main/.hgsubstate up to date?
When updating a subrepo, you always need to perform a commit on the main repo to begin using that subrepo revision. Therefore, you can't exactly do what you want from the subrepo itself, you will have to enter the main repo and execute a single command there.
from the command line:
(navigate to subrepo directory)
> hg tag <tagName>
(navigate to main repo directory)
> hg commit -m "updating to subrepo tag <tagName>"
After you have created the subrepo tag and updated the subrepo to that tag, performing a commit from the top level (ie: Main) should update .hgsubstate and does not require you to tag the Main repo. In fact, changing the revision of any subrepo should trigger a change in the .hgsubstate file, which can be committed in the main repo without a tag.
Something like below?
hg -R Sub tag tagname
hg -R Sub commit -m "Comitting tag"

How to create mercurial tag with a space

I would like to tag a changeset in Mercurial to 'Distribution 1.0'.
Unfortunatly I cannot find a command line command for creating a tag with a space in it's name.
When I use hg tag -m "Distribution 1.0" (double quotes) I get the help for the hg tag command indicating that I have an error.
When I use hg tag -m 'Distribution 1.0' a tag with the name 1.0' (single quotes) is created.
I know some tools don't like spaces alltogether, but if I edit my .hgtags file I can create a tag with a space.
Anybody knows how to do this?
Use hg tag "Distribution 1.0". The -m option provides the message for the commit that creates the tag, so you can use both: hg tag "Distribution 1.0" -m "Distribution 1.0".