from __future__ import absolute_import
-from binascii import hexlify
import sys
from bup import git, options
log("bup: error: commit %s not found.\n" % commit.decode('ascii'))
sys.exit(2)
- tag_file = git.repo(b'refs/tags/' + tag_name)
- try:
- tag = open(tag_file, 'wb')
- except OSError as e:
- log("bup: error: could not create tag '%s': %s" % (path_msg(tag_name), e))
- sys.exit(3)
- with tag as tag:
- tag.write(hexlify(hash))
- tag.write(b'\n')
+ git.update_ref(b'refs/tags/' + tag_name, hash, None, force=True)
return None
-def update_ref(refname, newval, oldval, repo_dir=None):
- """Update a repository reference."""
- if not oldval:
- oldval = b''
+def update_ref(refname, newval, oldval, repo_dir=None, force=False):
+ """Update a repository reference.
+
+ With force=True, don't care about the previous ref (oldval);
+ with force=False oldval must be either a sha1 or None (for an
+ entirely new branch)
+ """
+ if force:
+ assert oldval is None
+ oldarg = []
+ elif not oldval:
+ oldarg = [b'']
+ else:
+ oldarg = [hexlify(oldval)]
assert refname.startswith(b'refs/heads/') \
or refname.startswith(b'refs/tags/')
p = subprocess.Popen([b'git', b'update-ref', refname,
- hexlify(newval), hexlify(oldval)],
+ hexlify(newval)] + oldarg,
env=_gitenv(repo_dir),
close_fds=True)
_git_wait(b'git update-ref', p)