threads / patch / 14213

patch, 2 partsTry "stg sink" without applied patches

Subject: [StGit PATCH 1/2] Try "stg sink" without applied patches

## tl;dr

5 messages between Jun 29, 2008 and Jun 30, 2008. Diffs are folded; open one to read it.

replies: 4people: 2as markdown or json

Karl Hasselström· Jun 29, 2008, 22:45 UTC · lore

[StGit PATCH 0/2] Test+fix for bug 11887 (stg sink)

This should go on the stable branch, of course.
---
Karl Hasselström (2):
      Fix "stg sink" with no applied patches (bug 11887)
      Try "stg sink" without applied patches
 stgit/commands/sink.py |    8 ++++++--
 t/t1501-sink.sh        |   28 ++++++++++++++++++++++++++++
 2 files changed, 34 insertions(+), 2 deletions(-)
 create mode 100755 t/t1501-sink.sh
-- 
Karl Hasselström, kha@treskal.com
      www.treskal.com/kalle
Karl Hasselström· Jun 29, 2008, 22:45 UTC · re: Karl Hasselström · lore

It doesn't work, neither with an implicit nor an explicit patch to sink. This is bug 11887 in the bug tracker.

(The implicit sink testcase actually passes, but that's just because the test suite can't distinguish between a program bug and an orderly abort.)

The test was adapted from the script attached to the bug report, written by Erik Sandberg.

Signed-off-by: Karl Hasselström <kha@treskal.com>
---
 t/t1501-sink.sh |   28 ++++++++++++++++++++++++++++
 1 files changed, 28 insertions(+), 0 deletions(-)
 create mode 100755 t/t1501-sink.sh
Show changes to t/t1501-sink.sh +28 −0
diff --git a/t/t1501-sink.sh b/t/t1501-sink.sh
new file mode 100755
index 0000000..3872c4b
--- /dev/null
+++ b/t/t1501-sink.sh
@@ -0,0 +1,28 @@
+#!/bin/sh
+
+test_description='Test "stg sink"'
+
+. ./test-lib.sh
+
+test_expect_success 'Initialize StGit stack' '
+    echo 000 >> x &&
+    git add x &&
+    git commit -m initial &&
+    echo 000 >> y &&
+    git add y &&
+    git commit -m y &&
+    stg init &&
+    stg uncommit &&
+    stg pop
+'
+
+test_expect_success 'sink without applied patches' '
+    ! stg sink
+'
+
+test_expect_failure 'sink a specific patch without applied patches' '
+    stg sink y &&
+    test $(echo $(stg applied)) = "y"
+'
+
+test_done
Sverre Rabbelier· Jun 30, 2008, 07:53 UTC · re: Karl Hasselström · lore

Re: [StGit PATCH 1/2] Try "stg sink" without applied patches

On Mon, Jun 30, 2008 at 12:45 AM, Karl Hasselström <kha@treskal.com> wrote:
> (The implicit sink testcase actually passes, but that's just because
> the test suite can't distinguish between a program bug and an orderly
> abort.)
Yes it can, that's where "test_must_fail" comes in.
<snip>
> +test_expect_success 'sink without applied patches' '
> +    test_must_fail stg sink
> +'
> +
Like that.
-- 
Cheers,

Sverre Rabbelier
Karl Hasselström· Jun 30, 2008, 08:44 UTC · re: Sverre Rabbelier · lore

Re: [StGit PATCH 1/2] Try "stg sink" without applied patches

On 2008-06-30 09:53:22 +0200, Sverre Rabbelier wrote:
Show 14 quoted lines
> On Mon, Jun 30, 2008 at 12:45 AM, Karl Hasselström <kha@treskal.com> wrote:
>
> > (The implicit sink testcase actually passes, but that's just
> > because the test suite can't distinguish between a program bug and
> > an orderly abort.)
>
> Yes it can, that's where "test_must_fail" comes in.
>
> > +test_expect_success 'sink without applied patches' '
> > +    test_must_fail stg sink
> > +'
> > +
>
> Like that.
Well, except that
  1. test_must_fail doesn't even exist in StGit's test-lib.sh, because
     I've omitted it on purpose when stealing good stuff from git's
     test-lib.sh, because
  2. StGit is written in Python, so random bugs virtually never cause
     segfaults and stuff, they just raise various exceptions.

That said, StGit (especially in the master branch -- but this patch was against stable, where this is much less true) does exit with different exit codes depending on what kind of exception interrupted the program, and all exceptions not on a certain list cause it to exit with an exit code that means there's a bug (see the end of stgit/main.py for details). So writing a test_must_fail with sane behavior is perfectly doable and not actually all that hard.

Patch? :-)
-- 
Karl Hasselström, kha@treskal.com
      www.treskal.com/kalle
Karl Hasselström· Jun 29, 2008, 22:45 UTC · re: Karl Hasselström · lore

[StGit PATCH 2/2] Fix "stg sink" with no applied patches (bug 11887)

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 |    8 ++++++--
 t/t1501-sink.sh        |    2 +-
 2 files changed, 7 insertions(+), 3 deletions(-)
Show changes to 2 files +7 −3

stgit/commands/sink.py, t/t1501-sink.sh

diff --git a/stgit/commands/sink.py b/stgit/commands/sink.py
index 2167d87..d8f79b4 100644
--- a/stgit/commands/sink.py
+++ b/stgit/commands/sink.py
@@ -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:
diff --git a/t/t1501-sink.sh b/t/t1501-sink.sh
index 3872c4b..6af45fe 100755
--- a/t/t1501-sink.sh
+++ b/t/t1501-sink.sh
@@ -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"
 '

← back to recent threads