3 # https://sourceware.org/bugzilla/show_bug.cgi?id=26034
4 export "BUP_ARGV_0"="$0"
7 export "BUP_ARGV_${arg_i}"="$arg"
11 # Here to end of preamble replaced during install
12 bup_python="$(dirname "$0")/../../config/bin/python" || exit $?
13 exec "$bup_python" "$0"
17 from __future__ import absolute_import
19 # Intentionally replace the dirname "$0" that python prepends
21 sys.path[0] = os.path.dirname(os.path.realpath(__file__)) + '/..'
23 from binascii import hexlify
25 from bup import compat, git, options
26 from bup.compat import argv_bytes
27 from bup.helpers import debug1, handle_ctrl_c, log
28 from bup.io import byte_stream, path_msg
30 # FIXME: review for safe writes.
36 bup tag [-f] <tag name> <commit>
37 bup tag [-f] -d <tag name>
39 d,delete= Delete a tag
40 f,force Overwrite existing tag, or ignore missing tag when deleting
43 o = options.Options(optspec)
44 opt, flags, extra = o.parse(compat.argv[1:])
46 git.check_repo_or_die()
48 tags = [t for sublist in git.tags().values() for t in sublist]
51 # git.delete_ref() doesn't complain if a ref doesn't exist. We
52 # could implement this verification but we'd need to read in the
53 # contents of the tag file and pass the hash, and we already know
54 # about the tag's existance via "tags".
55 tag_name = argv_bytes(opt.delete)
56 if not opt.force and tag_name not in tags:
57 log("error: tag '%s' doesn't exist\n" % path_msg(tag_name))
59 tag_file = b'refs/tags/%s' % tag_name
60 git.delete_ref(tag_file)
66 out = byte_stream(sys.stdout)
71 o.fatal('expected commit ref and hash')
73 tag_name, commit = map(argv_bytes, extra[:2])
75 o.fatal("tag name must not be empty.")
76 debug1("args: tag name = %s; commit = %s\n"
77 % (path_msg(tag_name), commit.decode('ascii')))
79 if tag_name in tags and not opt.force:
80 log("bup: error: tag '%s' already exists\n" % path_msg(tag_name))
83 if tag_name.startswith(b'.'):
84 o.fatal("'%s' is not a valid tag name." % path_msg(tag_name))
87 hash = git.rev_parse(commit)
88 except git.GitError as e:
89 log("bup: error: %s" % e)
93 log("bup: error: commit %s not found.\n" % commit.decode('ascii'))
96 pL = git.PackIdxList(git.repo(b'objects/pack'))
97 if not pL.exists(hash):
98 log("bup: error: commit %s not found.\n" % commit.decode('ascii'))
101 tag_file = git.repo(b'refs/tags/' + tag_name)
103 tag = open(tag_file, 'wb')
105 log("bup: error: could not create tag '%s': %s" % (path_msg(tag_name), e))
108 tag.write(hexlify(hash))