diff mercurial/commands.py @ 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 8f8bb77d560e
children fda7bb480020
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'),