Mercurial > hg-stable
changeset 401:af4848f83e68
From: Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
From: Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
add hg tag command
Tweaks by mpm:
clean up error messages
handle non-existent .hgtags file
add tests
update test-help output
manifest hash: 569c7fe01193159919af2566e8f5089409ffad65
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.0 (GNU/Linux)
iD8DBQFCuMMwywK+sNU5EO8RAuUdAJ90TkT/D9lDOnEVAW2d3WT7K8Ct3QCggiJA
c9Qbd79K4UWKQAVkYq03cOY=
=SWS8
-----END PGP SIGNATURE-----
author | mpm@selenic.com |
---|---|
date | Tue, 21 Jun 2005 17:47:28 -0800 |
parents | 8b067bde6679 |
children | 2fe8d66e3075 |
files | mercurial/commands.py tests/test-help.out tests/test-tag tests/test-tag.out |
diffstat | 4 files changed, 79 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/commands.py Tue Jun 21 17:27:58 2005 -0800 +++ b/mercurial/commands.py Tue Jun 21 17:47:28 2005 -0800 @@ -566,6 +566,35 @@ for f in d: print "R", f for f in u: print "?", f +def tag(ui, repo, name, rev = None, **opts): + """add a tag for the current tip or a given revision""" + + if name == "tip": + ui.warn("abort: 'tip' is a reserved name!\n") + return -1 + + (c, a, d, u) = repo.diffdir(repo.root) + for x in (c, a, d, u): + if ".hgtags" in x: + ui.warn("abort: working copy of .hgtags is changed!\n") + ui.status("(please commit .hgtags manually)\n") + return -1 + + if rev: + r = hg.hex(repo.lookup(rev)) + else: + r = hg.hex(repo.changelog.tip()) + + add = 0 + if not os.path.exists(repo.wjoin(".hgtags")): add = 1 + repo.wfile(".hgtags", "a").write("%s %s\n" % (r, name)) + if add: repo.add([".hgtags"]) + + if not opts['text']: + opts['text'] = "Added tag %s for changeset %s" % (name, r) + + repo.commit([".hgtags"], opts['text'], opts['user'], opts['date']) + def tags(ui, repo): """list repository tags""" @@ -667,6 +696,10 @@ ('t', 'templates', "", 'template map')], "hg serve [options]"), "status": (status, [], 'hg status'), + "tag": (tag, [('t', 'text', "", 'commit text'), + ('d', 'date', "", 'date'), + ('u', 'user', "", 'user')], + 'hg tag [options] <name> [rev]'), "tags": (tags, [], 'hg tags'), "tip": (tip, [], 'hg tip'), "undo": (undo, [], 'hg undo'),
--- a/tests/test-help.out Tue Jun 21 17:27:58 2005 -0800 +++ b/tests/test-help.out Tue Jun 21 17:47:28 2005 -0800 @@ -26,6 +26,7 @@ remove remove the specified files on the next commit serve export the repository via HTTP status show changed files in the working directory + tag add a tag for the current tip or a given revision tags list repository tags tip show the tip revision undo undo the last transaction @@ -74,6 +75,7 @@ remove remove the specified files on the next commit serve export the repository via HTTP status show changed files in the working directory + tag add a tag for the current tip or a given revision tags list repository tags tip show the tip revision undo undo the last transaction
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test-tag Tue Jun 21 17:47:28 2005 -0800 @@ -0,0 +1,13 @@ +#!/bin/sh -x + +hg init +echo a > a +hg add a +hg commit -t "test" -u test -d "0 0" +hg history +hg tag -u test -d "0 0" "bleah" +hg history + +echo foo >> .hgtags +hg tag -u test -d "0 0" "bleah2" || echo "failed" +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test-tag.out Tue Jun 21 17:47:28 2005 -0800 @@ -0,0 +1,31 @@ ++ hg init ++ echo a ++ hg add a ++ hg commit -t test -u test -d '0 0' ++ hg history +changeset: 0:acb14030fe0a21b60322c440ad2d20cf7685a376 +tag: tip +user: test +date: Thu Jan 1 00:00:00 1970 +summary: test + ++ hg tag -u test -d '0 0' bleah ++ hg history +changeset: 1:863197ef03781c4fc00276d83eb66c4cb9cd91df +tag: tip +user: test +date: Thu Jan 1 00:00:00 1970 +summary: Added tag bleah for changeset acb14030fe0a21b60322c440ad2d20cf7685a376 + +changeset: 0:acb14030fe0a21b60322c440ad2d20cf7685a376 +tag: bleah +user: test +date: Thu Jan 1 00:00:00 1970 +summary: test + ++ echo foo ++ hg tag -u test -d '0 0' bleah2 +abort: working copy of .hgtags is changed! +(please commit .hgtags manually) ++ echo failed +failed