From: Ben Kelly Date: Sat, 9 Nov 2013 19:21:04 +0000 (-0500) Subject: Add 'tag -f' support. X-Git-Tag: 0.25-rc4~9 X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?p=bup.git;a=commitdiff_plain;h=7e6aaa38f37c37c99bef07158336dfac7e587407 Add 'tag -f' support. 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 [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 --- diff --git a/Documentation/bup-tag.md b/Documentation/bup-tag.md index bd6a8c9..78fe37e 100644 --- a/Documentation/bup-tag.md +++ b/Documentation/bup-tag.md @@ -10,9 +10,9 @@ bup-tag - tag a commit in the bup repository bup tag -bup tag \ \ +bup tag [-f] \ \ -bup tag -d \ +bup tag -d [-f] \ # 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 diff --git a/cmd/tag-cmd.py b/cmd/tag-cmd.py index 17037b3..007cbb7 100755 --- a/cmd/tag-cmd.py +++ b/cmd/tag-cmd.py @@ -14,10 +14,11 @@ handle_ctrl_c() optspec = """ bup tag -bup tag -bup tag -d +bup tag [-f] +bup tag -d [-f] -- 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) diff --git a/t/test.sh b/t/test.sh index 514ef58..f74e4a3 100755 --- 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"