`stg delete --empty` deletes all empty patches in series. Command does nothing and exits with zero code if all patches are not empty. --empty option can be useful in this workflow: * you work on the patches * you send patches to upstream (using stg export or stg mail) * patches are committed to upstream after a while * you do `git fetch && stg rebase origin` * `stg rebase origin` makes applied to upstrem local patches empty * now you can use stg delete --empty to cleanup Signed-off-by: Stepan Koltsov <stepan.koltsov@xxxxxxxxxxxxx> --- stgit/commands/delete.py | 30 ++++++++++++++++++++++++-- t/t1603-delete-empty.sh | 51 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+), 3 deletions(-) create mode 100755 t/t1603-delete-empty.sh diff --git a/stgit/commands/delete.py b/stgit/commands/delete.py index 84a057e..414f456 100644 --- a/stgit/commands/delete.py +++ b/stgit/commands/delete.py @@ -1,3 +1,4 @@ +from stgit.out import MessagePrinter __copyright__ = """ Copyright (C) 2005, Catalin Marinas <catalin.marinas@xxxxxxxxx> @@ -40,7 +41,9 @@ options = [ opt('-b', '--branch', args = [argparse.stg_branches], short = 'Use BRANCH instead of the default branch'), opt('-t', '--top', action = 'store_true', - short = 'Delete top patch'),] + short = 'Delete top patch'), + opt('-e', '--empty', action = 'store_true', + short = 'Delete empty patches')] directory = common.DirectoryHasRepositoryLib() @@ -51,8 +54,17 @@ def func(parser, options, args): iw = None # can't use index/workdir to manipulate another branch else: iw = stack.repository.default_iw - if args and options.top: - parser.error('Either --top or patches must be specified') + + mode_count = 0 + if args: + mode_count += 1 + if options.top: + mode_count += 1 + if options.empty: + mode_count += 1 + + if mode_count > 1: + parser.error('Either --top or --empty or patches must be specified') elif args: patches = set(common.parse_patches(args, list(stack.patchorder.all), len(stack.patchorder.applied))) @@ -62,6 +74,16 @@ def func(parser, options, args): patches = set([applied[-1]]) else: raise common.CmdException, 'No patches applied' + + elif options.empty: + patches_list = [] + for p in stack.patchorder.all: + if stack.patches.get(p).is_empty(): + patches_list.append(p) + if not patches_list: + out.info('No empty patches') + return 0 + patches = set(patches_list) else: parser.error('No patches specified') @@ -86,3 +108,5 @@ def func(parser, options, args): except transaction.TransactionHalted: pass return trans.run(iw) + +out = MessagePrinter() diff --git a/t/t1603-delete-empty.sh b/t/t1603-delete-empty.sh new file mode 100755 index 0000000..8a5630a --- /dev/null +++ b/t/t1603-delete-empty.sh @@ -0,0 +1,51 @@ +#!/bin/sh -e +# Copyright (c) 2012 Stepan Koltsov +test_description='Test the delete --empty command.' + +. ./test-lib.sh + +test_expect_success \ + 'Initialize the StGIT repository' \ + 'stg init' + +test_expect_success \ + 'Create first real patch' \ + ' + stg new foo -m foo && + echo foo > foo.txt && + stg add foo.txt && + stg refresh + ' + +test_expect_success \ + 'Create second empty patch' \ + 'stg new bar -m bar' + +test_expect_success \ + 'Create third real patch' \ + ' + stg new baz -m foo && + echo baz > baz.txt && + stg add baz.txt && + stg refresh + ' + +test_expect_success \ + 'Create forth empty patch' \ + 'stg new qux -m qux' + +test_expect_success \ + 'Delete empty patches' \ + ' + stg delete --empty && + [ "$(echo $(stg series --noprefix))" = "foo baz" ] + ' + +test_expect_success \ + 'Delete empty patches again (i. e. delete nothing)' \ + ' + stg delete --empty && + [ "$(echo $(stg series --noprefix))" = "foo baz" ] + ' + +test_done -- 1.7.9.1 -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html