]> arthur.barton.de Git - bup.git/commitdiff
tag-cmd.py: use git update-ref to delete tags
authorGabriel Filion <gabster@lelutin.ca>
Sat, 15 Nov 2014 22:06:08 +0000 (17:06 -0500)
committerRob Browning <rlb@defaultvalue.org>
Sun, 16 Nov 2014 19:34:22 +0000 (13:34 -0600)
Sometimes tags can be elsewhere than in the refs/tags/ directory. This
can happen if git pack-refs --all was used.

The current code chokes on such a situation. Since git update-ref
already knows about this subtlety, let it handle the deletion.

Signed-off-by: Gabriel Filion <gabster@lelutin.ca>
Reviewed-by: Rob Browning <rlb@defaultvalue.org>
Tested-by: Rob Browning <rlb@defaultvalue.org>
cmd/tag-cmd.py
lib/bup/git.py

index 28fa328b6d5e5048687d571854f12e31b9e79707..5a3108f2236c0d9ba291acbae0e350cf41a6cf58 100755 (executable)
@@ -27,25 +27,20 @@ o = options.Options(optspec)
 
 git.check_repo_or_die()
 
-if opt.delete:
-    tag_file = git.repo('refs/tags/%s' % opt.delete)
-    debug1("tag file: %s\n" % tag_file)
-    if not os.path.exists(tag_file):
-        if opt.force:
-            sys.exit(0)
-        log("bup: error: tag '%s' not found.\n" % opt.delete)
-        sys.exit(1)
+tags = [t for sublist in git.tags().values() for t in sublist]
 
-    try:
-        os.unlink(tag_file)
-    except OSError, e:
-        log("bup: error: unable to delete tag '%s': %s" % (opt.delete, e))
+if opt.delete:
+    # git.delete_ref() doesn't complain if a ref doesn't exist.  We
+    # could implement this verification but we'd need to read in the
+    # contents of the tag file and pass the hash, and we already know
+    # about the tag's existance via "tags".
+    if not opt.force and opt.delete not in tags:
+        log("error: tag '%s' doesn't exist\n" % opt.delete)
         sys.exit(1)
-
+    tag_file = 'refs/tags/%s' % opt.delete
+    git.delete_ref(tag_file)
     sys.exit(0)
 
-tags = [t for sublist in git.tags().values() for t in sublist]
-
 if not extra:
     for t in tags:
         print t
index d09fc3f5b21f5276e99a730c210ef6e7c56c44c2..afd1b3614816b5780fe1d0a6beece597e14dd563 100644 (file)
@@ -883,6 +883,14 @@ def update_ref(refname, newval, oldval, repo_dir=None):
     _git_wait('git update-ref', p)
 
 
+def delete_ref(refname):
+    """Delete a repository reference."""
+    assert(refname.startswith('refs/'))
+    p = subprocess.Popen(['git', 'update-ref', '-d', refname],
+                         preexec_fn = _gitenv())
+    _git_wait('git update-ref', p)
+
+
 def guess_repo(path=None):
     """Set the path value in the global variable "repodir".
     This makes bup look for an existing bup repository, but not fail if a