3 bup_python="$(dirname "$0")/bup-python" || exit $?
4 exec "$bup_python" "$0" ${1+"$@"}
8 from __future__ import absolute_import, print_function
11 from bup import git, options
12 from bup.helpers import debug1, handle_ctrl_c, log
14 # FIXME: review for safe writes.
20 bup tag [-f] <tag name> <commit>
21 bup tag [-f] -d <tag name>
23 d,delete= Delete a tag
24 f,force Overwrite existing tag, or ignore missing tag when deleting
27 o = options.Options(optspec)
28 (opt, flags, extra) = o.parse(sys.argv[1:])
30 git.check_repo_or_die()
32 tags = [t for sublist in git.tags().values() for t in sublist]
35 # git.delete_ref() doesn't complain if a ref doesn't exist. We
36 # could implement this verification but we'd need to read in the
37 # contents of the tag file and pass the hash, and we already know
38 # about the tag's existance via "tags".
39 if not opt.force and opt.delete not in tags:
40 log("error: tag '%s' doesn't exist\n" % opt.delete)
42 tag_file = 'refs/tags/%s' % opt.delete
43 git.delete_ref(tag_file)
51 o.fatal('no commit ref or hash given.')
53 (tag_name, commit) = extra[:2]
55 o.fatal("tag name must not be empty.")
56 debug1("args: tag name = %s; commit = %s\n" % (tag_name, commit))
58 if tag_name in tags and not opt.force:
59 log("bup: error: tag '%s' already exists\n" % tag_name)
62 if tag_name.startswith('.'):
63 o.fatal("'%s' is not a valid tag name." % tag_name)
66 hash = git.rev_parse(commit)
67 except git.GitError as e:
68 log("bup: error: %s" % e)
72 log("bup: error: commit %s not found.\n" % commit)
75 pL = git.PackIdxList(git.repo('objects/pack'))
76 if not pL.exists(hash):
77 log("bup: error: commit %s not found.\n" % commit)
80 tag_file = git.repo('refs/tags/%s' % tag_name)
82 tag = open(tag_file, 'w')
84 log("bup: error: could not create tag '%s': %s" % (tag_name, e))
87 tag.write(hash.encode('hex'))