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")/bup-python" || exit $?
13 exec "$bup_python" "$0"
17 from __future__ import absolute_import
18 from binascii import hexlify
21 from bup import compat, git, options
22 from bup.compat import argv_bytes
23 from bup.helpers import debug1, handle_ctrl_c, log
24 from bup.io import byte_stream, path_msg
26 # FIXME: review for safe writes.
32 bup tag [-f] <tag name> <commit>
33 bup tag [-f] -d <tag name>
35 d,delete= Delete a tag
36 f,force Overwrite existing tag, or ignore missing tag when deleting
39 o = options.Options(optspec)
40 opt, flags, extra = o.parse(compat.argv[1:])
42 git.check_repo_or_die()
44 tags = [t for sublist in git.tags().values() for t in sublist]
47 # git.delete_ref() doesn't complain if a ref doesn't exist. We
48 # could implement this verification but we'd need to read in the
49 # contents of the tag file and pass the hash, and we already know
50 # about the tag's existance via "tags".
51 tag_name = argv_bytes(opt.delete)
52 if not opt.force and tag_name not in tags:
53 log("error: tag '%s' doesn't exist\n" % path_msg(tag_name))
55 tag_file = b'refs/tags/%s' % tag_name
56 git.delete_ref(tag_file)
62 out = byte_stream(sys.stdout)
67 o.fatal('expected commit ref and hash')
69 tag_name, commit = map(argv_bytes, extra[:2])
71 o.fatal("tag name must not be empty.")
72 debug1("args: tag name = %s; commit = %s\n"
73 % (path_msg(tag_name), commit.decode('ascii')))
75 if tag_name in tags and not opt.force:
76 log("bup: error: tag '%s' already exists\n" % path_msg(tag_name))
79 if tag_name.startswith(b'.'):
80 o.fatal("'%s' is not a valid tag name." % path_msg(tag_name))
83 hash = git.rev_parse(commit)
84 except git.GitError as e:
85 log("bup: error: %s" % e)
89 log("bup: error: commit %s not found.\n" % commit.decode('ascii'))
92 pL = git.PackIdxList(git.repo(b'objects/pack'))
93 if not pL.exists(hash):
94 log("bup: error: commit %s not found.\n" % commit.decode('ascii'))
97 tag_file = git.repo(b'refs/tags/' + tag_name)
99 tag = open(tag_file, 'wb')
101 log("bup: error: could not create tag '%s': %s" % (path_msg(tag_name), e))
104 tag.write(hexlify(hash))