Also document what "-n<negative>" does.
Added some push tests to t1203-pop.sh and renamed it t1208-push-and-pop.sh.
Signed-off-by: Gustav Hållberg <gustav@virtutech.com>
Signed-off-by: Karl Wiberg <kha@treskal.com>
opt('-a', '--all', action = 'store_true',
short = 'Pop all the applied patches'),
opt('-n', '--number', type = 'int',
- short = 'Pop the specified number of patches')
+ short = 'Pop the specified number of patches', long = '''
+ Pop the specified number of patches.
+
+ With a negative number, pop all but that many patches.'''),
] + argparse.keep_option()
directory = common.DirectoryHasRepositoryLib()
trans = transaction.StackTransaction(stack, 'pop',
check_clean_iw = clean_iw)
+ if options.number == 0:
+ # explicitly allow this without any warning/error message
+ return
+
if not trans.applied:
raise common.CmdException('No patches applied')
if options.all:
patches = trans.applied
- elif options.number:
+ elif options.number is not None:
# reverse it twice to also work with negative or bigger than
# the length numbers
patches = trans.applied[::-1][:options.number][::-1]
opt('-a', '--all', action = 'store_true',
short = 'Push all the unapplied patches'),
opt('-n', '--number', type = 'int',
- short = 'Push the specified number of patches'),
+ short = 'Push the specified number of patches', long = '''
+ Push the specified number of patches.
+
+ With a negative number, push all but that many patches.'''),
opt('--reverse', action = 'store_true',
short = 'Push the patches in reverse order'),
opt('--set-tree', action = 'store_true',
trans = transaction.StackTransaction(stack, 'pop',
check_clean_iw = clean_iw)
+ if options.number == 0:
+ # explicitly allow this without any warning/error message
+ return
+
if not trans.unapplied:
raise common.CmdException('No patches to push')
if options.all:
patches = list(trans.unapplied)
- elif options.number:
+ elif options.number is not None:
patches = trans.unapplied[:options.number]
elif not args:
patches = [trans.unapplied[0]]
+++ /dev/null
-#!/bin/sh
-# Copyright (c) 2007 Karl Hasselström
-test_description='Test the pop command'
-. ./test-lib.sh
-
-test_expect_success \
- 'Initialize the StGIT repository' \
- 'stg init'
-
-test_expect_success \
- 'Create ten patches' '
- for i in 0 1 2 3 4 5 6 7 8 9; do
- stg new p$i -m p$i;
- done &&
- [ "$(echo $(stg series --applied --noprefix))" = "p0 p1 p2 p3 p4 p5 p6 p7 p8 p9" ] &&
- [ "$(echo $(stg series --unapplied --noprefix))" = "" ]
-'
-
-test_expect_success \
- 'Pop half the patches' '
- stg pop -n 5 &&
- [ "$(echo $(stg series --applied --noprefix))" = "p0 p1 p2 p3 p4" ] &&
- [ "$(echo $(stg series --unapplied --noprefix))" = "p5 p6 p7 p8 p9" ]
-'
-
-test_expect_success \
- 'Pop the remaining patches' '
- stg pop -a &&
- [ "$(echo $(stg series --applied --noprefix))" = "" ] &&
- [ "$(echo $(stg series --unapplied --noprefix))" = "p0 p1 p2 p3 p4 p5 p6 p7 p8 p9" ]
-'
-
-test_done
--- /dev/null
+#!/bin/sh
+# Copyright (c) 2007 Karl Hasselström
+test_description='Test the push and pop commands'
+. ./test-lib.sh
+
+test_expect_success \
+ 'Initialize the StGIT repository' \
+ 'stg init'
+
+test_expect_success \
+ 'Create ten patches' '
+ for i in 0 1 2 3 4 5 6 7 8 9; do
+ stg new p$i -m p$i;
+ done &&
+ [ "$(echo $(stg series --applied --noprefix))" = "p0 p1 p2 p3 p4 p5 p6 p7 p8 p9" ] &&
+ [ "$(echo $(stg series --unapplied --noprefix))" = "" ]
+'
+
+test_expect_success \
+ 'Pop three patches' '
+ stg pop -n 3 &&
+ [ "$(echo $(stg series --applied --noprefix))" = "p0 p1 p2 p3 p4 p5 p6" ] &&
+ [ "$(echo $(stg series --unapplied --noprefix))" = "p7 p8 p9" ]
+'
+
+test_expect_success \
+ 'Pop the remaining patches' '
+ stg pop -a &&
+ [ "$(echo $(stg series --applied --noprefix))" = "" ] &&
+ [ "$(echo $(stg series --unapplied --noprefix))" = "p0 p1 p2 p3 p4 p5 p6 p7 p8 p9" ]
+'
+
+test_expect_success \
+ 'Push them back' '
+ stg push -a &&
+ [ "$(echo $(stg series --applied --noprefix))" = "p0 p1 p2 p3 p4 p5 p6 p7 p8 p9" ] &&
+ [ "$(echo $(stg series --unapplied --noprefix))" = "" ]
+'
+
+test_expect_success \
+ 'Pop all but seven patches' '
+ stg pop -n -7 &&
+ [ "$(echo $(stg series --applied --noprefix))" = "p0 p1 p2 p3 p4 p5 p6" ] &&
+ [ "$(echo $(stg series --unapplied --noprefix))" = "p7 p8 p9" ]
+'
+
+test_expect_success \
+ 'Pop no patches (quietly)' '
+ [ -z "$(stg pop -n 0 2>&1)" ] &&
+ [ "$(echo $(stg series --applied --noprefix))" = "p0 p1 p2 p3 p4 p5 p6" ] &&
+ [ "$(echo $(stg series --unapplied --noprefix))" = "p7 p8 p9" ]
+'
+
+test_expect_success \
+ 'Pop remaining seven patches' '
+ stg pop -n 7 &&
+ [ "$(echo $(stg series --applied --noprefix))" = "" ] &&
+ [ "$(echo $(stg series --unapplied --noprefix))" = "p0 p1 p2 p3 p4 p5 p6 p7 p8 p9" ]
+'
+
+test_expect_success \
+ 'Push two patches' '
+ stg push -n 2 &&
+ [ "$(echo $(stg series --applied --noprefix))" = "p0 p1" ] &&
+ [ "$(echo $(stg series --unapplied --noprefix))" = "p2 p3 p4 p5 p6 p7 p8 p9" ]
+'
+
+test_expect_success \
+ 'Push no patches (quietly)' '
+ [ -z "$(stg push -n 0 2>&1)" ] &&
+ [ "$(echo $(stg series --applied --noprefix))" = "p0 p1" ] &&
+ [ "$(echo $(stg series --unapplied --noprefix))" = "p2 p3 p4 p5 p6 p7 p8 p9" ]
+'
+
+test_expect_success \
+ 'Push all but three patches' '
+ stg push -n -3 &&
+ [ "$(echo $(stg series --applied --noprefix))" = "p0 p1 p2 p3 p4 p5 p6" ] &&
+ [ "$(echo $(stg series --unapplied --noprefix))" = "p7 p8 p9" ]
+'
+
+test_done