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
18 from binascii import hexlify
21 sys.path[:0] = [os.path.dirname(os.path.realpath(__file__)) + '/..']
23 from bup import compat, git, options
24 from bup.compat import argv_bytes
25 from bup.helpers import debug1, handle_ctrl_c, log
26 from bup.io import byte_stream, path_msg
28 # FIXME: review for safe writes.
34 bup tag [-f] <tag name> <commit>
35 bup tag [-f] -d <tag name>
37 d,delete= Delete a tag
38 f,force Overwrite existing tag, or ignore missing tag when deleting
41 o = options.Options(optspec)
42 opt, flags, extra = o.parse(compat.argv[1:])
44 git.check_repo_or_die()
46 tags = [t for sublist in git.tags().values() for t in sublist]
49 # git.delete_ref() doesn't complain if a ref doesn't exist. We
50 # could implement this verification but we'd need to read in the
51 # contents of the tag file and pass the hash, and we already know
52 # about the tag's existance via "tags".
53 tag_name = argv_bytes(opt.delete)
54 if not opt.force and tag_name not in tags:
55 log("error: tag '%s' doesn't exist\n" % path_msg(tag_name))
57 tag_file = b'refs/tags/%s' % tag_name
58 git.delete_ref(tag_file)
64 out = byte_stream(sys.stdout)
69 o.fatal('expected commit ref and hash')
71 tag_name, commit = map(argv_bytes, extra[:2])
73 o.fatal("tag name must not be empty.")
74 debug1("args: tag name = %s; commit = %s\n"
75 % (path_msg(tag_name), commit.decode('ascii')))
77 if tag_name in tags and not opt.force:
78 log("bup: error: tag '%s' already exists\n" % path_msg(tag_name))
81 if tag_name.startswith(b'.'):
82 o.fatal("'%s' is not a valid tag name." % path_msg(tag_name))
85 hash = git.rev_parse(commit)
86 except git.GitError as e:
87 log("bup: error: %s" % e)
91 log("bup: error: commit %s not found.\n" % commit.decode('ascii'))
94 pL = git.PackIdxList(git.repo(b'objects/pack'))
95 if not pL.exists(hash):
96 log("bup: error: commit %s not found.\n" % commit.decode('ascii'))
99 tag_file = git.repo(b'refs/tags/' + tag_name)
101 tag = open(tag_file, 'wb')
103 log("bup: error: could not create tag '%s': %s" % (path_msg(tag_name), e))
106 tag.write(hexlify(hash))