]> arthur.barton.de Git - bup.git/commitdiff
Add 'tag -f' support.
authorBen Kelly <bk@ancilla.ca>
Sat, 9 Nov 2013 19:21:04 +0000 (14:21 -0500)
committerRob Browning <rlb@defaultvalue.org>
Sat, 9 Nov 2013 20:45:04 +0000 (14:45 -0600)
Add a new flag, -f/--force, to bup tag. By analogy with 'git tag',
'bup tag -f foo commit' will create tag *foo* even if a tag with that
name already exists; the existing tag will be silently overwritten.

By analogy with 'rm -f', add 'bup tag -d -f'. All this does is
suppress the error when you attempt to 'bup tag -d' a tag that doesn't
exist; it is primarily for use in scripts that want to delete a tag
that may or may not exist in the first place without 'bup tag'
reporting a failure.

Signed-off-by: Ben Kelly <btk@google.com>
[rlb@defaultvalue.org: add missing "tag" and wrap text in bup-tag.md;
 put "-d" first in tag-cmd.py optspec line and bup-tag.md; adjust
 commit message.]
Signed-off-by: Rob Browning <rlb@defaultvalue.org>
Documentation/bup-tag.md
cmd/tag-cmd.py
t/test.sh

index bd6a8c95430353ee7135abfeb40d35f6b91bc486..78fe37ec995af54583c5ecf92000e1ac7c3e96d5 100644 (file)
@@ -10,9 +10,9 @@ bup-tag - tag a commit in the bup repository
 
 bup tag
 
-bup tag \<tag name\> \<committish\>
+bup tag [-f] \<tag name\> \<committish\>
 
-bup tag -d \<tag name\>
+bup tag -d [-f] \<tag name\>
 
 # DESCRIPTION
 
@@ -43,6 +43,10 @@ through /.tag/important as long as the tag is not deleted.
 -d, \--delete
 :   delete a tag
 
+-f, \--force
+:  Overwrite the named tag even if it already exists. With -f, don't
+   report a missing tag as an error.
+
 # EXAMPLE
     
     $ bup tag new-puppet-version hostx-backup
index 17037b319b7c066f3ea15eec4411cbaa0ddeb1a3..007cbb74127765e43e8177e708a0cd341937e701 100755 (executable)
@@ -14,10 +14,11 @@ handle_ctrl_c()
 
 optspec = """
 bup tag
-bup tag <tag name> <commit>
-bup tag -d <tag name>
+bup tag [-f] <tag name> <commit>
+bup tag -d [-f] <tag name>
 --
 d,delete=   Delete a tag
+f,force     Overwrite existing tag, or 'delete' a tag that doesn't exist
 """
 
 o = options.Options(optspec)
@@ -29,6 +30,8 @@ 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)
 
@@ -54,7 +57,7 @@ if not tag_name:
     o.fatal("tag name must not be empty.")
 debug1("args: tag name = %s; commit = %s\n" % (tag_name, commit))
 
-if tag_name in tags:
+if tag_name in tags and not opt.force:
     log("bup: error: tag '%s' already exists\n" % tag_name)
     sys.exit(1)
 
index 514ef58ab4bba3ebf13997d5791cfd506f76c073..f74e4a3dd14259324c3e556c63dc25777ab8ac30 100755 (executable)
--- a/t/test.sh
+++ b/t/test.sh
@@ -297,7 +297,11 @@ WVFAIL bup tag v0.n non-existant 2>/dev/null
 WVPASSEQ "$(bup tag)" ""
 WVPASS bup tag v0.1 master
 WVPASSEQ "$(bup tag)" "v0.1"
+WVFAIL bup tag v0.1 master
+WVPASS bup tag -f v0.1 master
 WVPASS bup tag -d v0.1
+WVPASS bup tag -f -d v0.1
+WVFAIL bup tag -d v0.1
 
 # This section destroys data in the bup repository, so it is done last.
 WVSTART "fsck"