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(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.\n" % opt.delete)
38 log("bup: error: unable to delete tag '%s': %s" % (opt.delete, e))
43 tags = [t for sublist in git.tags().values() for t in sublist]
50 o.fatal('no commit ref or hash given.')
52 (tag_name, commit) = extra[:2]
54 o.fatal("tag name must not be empty.")
55 debug1("args: tag name = %s; commit = %s\n" % (tag_name, commit))
58 log("bup: error: tag '%s' already exists\n" % tag_name)
61 if tag_name.startswith('.'):
62 o.fatal("'%s' is not a valid tag name." % tag_name)
65 hash = git.rev_parse(commit)
66 except git.GitError, e:
67 log("bup: error: %s" % e)
71 log("bup: error: commit %s not found.\n" % commit)
74 pL = git.PackIdxList(git.repo('objects/pack'))
75 if not pL.exists(hash):
76 log("bup: error: commit %s not found.\n" % commit)
79 tag_file = git.repo('refs/tags/%s' % tag_name)
81 tag = file(tag_file, 'w')
83 log("bup: error: could not create tag '%s': %s" % (tag_name, e))
86 tag.write(hash.encode('hex'))