3 bup_python="$(dirname "$0")/bup-python" || exit $?
4 exec "$bup_python" "$0" ${1+"$@"}
10 from bup import git, options
11 from bup.helpers import debug1, handle_ctrl_c, log
13 # FIXME: review for safe writes.
19 bup tag [-f] <tag name> <commit>
20 bup tag [-f] -d <tag name>
22 d,delete= Delete a tag
23 f,force Overwrite existing tag, or ignore missing tag when deleting
26 o = options.Options(optspec)
27 (opt, flags, extra) = o.parse(sys.argv[1:])
29 git.check_repo_or_die()
31 tags = [t for sublist in git.tags().values() for t in sublist]
34 # git.delete_ref() doesn't complain if a ref doesn't exist. We
35 # could implement this verification but we'd need to read in the
36 # contents of the tag file and pass the hash, and we already know
37 # about the tag's existance via "tags".
38 if not opt.force and opt.delete not in tags:
39 log("error: tag '%s' doesn't exist\n" % opt.delete)
41 tag_file = 'refs/tags/%s' % opt.delete
42 git.delete_ref(tag_file)
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))
57 if tag_name in tags and not opt.force:
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 as 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'))