Fix "stg sink" with no applied patches (bug 11887)
authorKarl Hasselström <kha@treskal.com>
Sun, 29 Jun 2008 22:36:24 +0000 (00:36 +0200)
committerKarl Hasselström <kha@treskal.com>
Sun, 29 Jun 2008 22:38:55 +0000 (00:38 +0200)
There were two separate things to fix: bail out if we need a current
patch and there isn't one (because there are no applied patches), and
make sure we don't try to pop patches that don't exist.

Signed-off-by: Karl Hasselström <kha@treskal.com>
stgit/commands/sink.py
t/t1501-sink.sh

index 2167d87..d8f79b4 100644 (file)
@@ -58,9 +58,13 @@ def func(parser, options, args):
     if len(args) > 0:
         patches = parse_patches(args, all)
     else:
-        patches = [ crt_series.get_current() ]
+        current = crt_series.get_current()
+        if not current:
+            raise CmdException('No patch applied')
+        patches = [current]
 
-    crt_series.pop_patch(options.to or oldapplied[0])
+    if oldapplied:
+        crt_series.pop_patch(options.to or oldapplied[0])
     push_patches(crt_series, patches)
 
     if not options.nopush:
index 3872c4b..6af45fe 100755 (executable)
@@ -20,7 +20,7 @@ test_expect_success 'sink without applied patches' '
     ! stg sink
 '
 
-test_expect_failure 'sink a specific patch without applied patches' '
+test_expect_success 'sink a specific patch without applied patches' '
     stg sink y &&
     test $(echo $(stg applied)) = "y"
 '