push/pop: Allow "-n0" to do nothing
authorGustav Hållberg <gustav@virtutech.com>
Wed, 28 Oct 2009 11:21:20 +0000 (12:21 +0100)
committerKarl Wiberg <kha@treskal.com>
Wed, 28 Oct 2009 11:22:06 +0000 (12:22 +0100)
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>
stgit/commands/pop.py
stgit/commands/push.py
t/t1203-pop.sh [deleted file]
t/t1208-push-and-pop.sh [new file with mode: 0755]

index eace090..deb7290 100644 (file)
@@ -39,7 +39,10 @@ options = [
     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()
@@ -52,12 +55,16 @@ def func(parser, options, args):
     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]
index d5e02e0..7ec7d08 100644 (file)
@@ -41,7 +41,10 @@ options = [
     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',
@@ -67,12 +70,16 @@ def func(parser, options, args):
     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]]
diff --git a/t/t1203-pop.sh b/t/t1203-pop.sh
deleted file mode 100755 (executable)
index e1ed577..0000000
+++ /dev/null
@@ -1,33 +0,0 @@
-#!/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
diff --git a/t/t1208-push-and-pop.sh b/t/t1208-push-and-pop.sh
new file mode 100755 (executable)
index 0000000..10cb8d3
--- /dev/null
@@ -0,0 +1,82 @@
+#!/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