2 """Tag a commit in the bup repository.
3 Creating a tag on a commit can be used for avoiding automatic cleanup from
4 removing this commit due to old age.
9 from bup import git, options
10 from bup.helpers import *
17 bup tag <tag name> <commit>
20 d,delete= Delete a tag
23 o = options.Options('bup tag', optspec)
24 (opt, flags, extra) = o.parse(sys.argv[1:])
26 git.check_repo_or_die()
29 tag_file = git.repo('refs/tags/%s' % opt.delete)
30 debug1("tag file: %s\n" % tag_file)
31 if not os.path.exists(tag_file):
32 log("bup: error: tag '%s' not found." % opt.delete)
38 log("bup: error: unable to delete tag: %s" % e)
44 for (t, dummy) in git.list_refs():
45 if t.startswith('refs/tags/'):
53 log('bup: error: no ref or hash given.')
58 debug1("from args: tag name = %s; commit = %s\n" % (tag_name, commit))
61 log("bup: error: tag '%s' already exists" % tag_name)
64 hash = git.rev_parse(commit)
66 log("bup: error: commit %s not found." % commit)
69 pL = git.PackIdxList(git.repo('objects/pack'))
70 if not pL.exists(hash):
71 log("bup: error: commit %s not found." % commit)
74 tag_file = git.repo('refs/tags/%s' % tag_name)
76 tag = file(tag_file, 'w')
78 log('bup: error: could not create tag %s: %s' % (tag_name, e))
81 tag.write(hash.encode('hex'))