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

5 messages from 2008-06-29 to 2008-06-30. Participants: Karl Hasselström, Sverre Rabbelier.
Thread: https://gitlist.dev/t/14213

## Karl Hasselström, 2008-06-29 22:45

Subject: [StGit PATCH 0/2] Test+fix for bug 11887 (stg sink)
Message-ID: <20080629224440.9267.3591.stgit@yoghurt>
URL: https://gitlist.dev/e/20080629224440.9267.3591.stgit%40yoghurt

```
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, 2008-06-29 22:45

Subject: [StGit PATCH 1/2] Try "stg sink" without applied patches
Message-ID: <20080629224541.9267.19258.stgit@yoghurt>
URL: https://gitlist.dev/e/20080629224541.9267.19258.stgit%40yoghurt
In-Reply-To: <20080629224440.9267.3591.stgit@yoghurt>

```
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


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

```

## Karl Hasselström, 2008-06-29 22:45

Subject: [StGit PATCH 2/2] Fix "stg sink" with no applied patches (bug 11887)
Message-ID: <20080629224547.9267.92299.stgit@yoghurt>
URL: https://gitlist.dev/e/20080629224547.9267.92299.stgit%40yoghurt
In-Reply-To: <20080629224440.9267.3591.stgit@yoghurt>

```
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(-)


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"
 '

```

## Sverre Rabbelier, 2008-06-30 07:53

Subject: Re: [StGit PATCH 1/2] Try "stg sink" without applied patches
Message-ID: <bd6139dc0806300053m4325104dx145cd8840c630453@mail.gmail.com>
URL: https://gitlist.dev/e/bd6139dc0806300053m4325104dx145cd8840c630453%40mail.gmail.com
In-Reply-To: <20080629224541.9267.19258.stgit@yoghurt>

```
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, 2008-06-30 08:44

Subject: Re: [StGit PATCH 1/2] Try "stg sink" without applied patches
Message-ID: <20080630084433.GA20712@diana.vm.bytemark.co.uk>
URL: https://gitlist.dev/e/20080630084433.GA20712%40diana.vm.bytemark.co.uk
In-Reply-To: <bd6139dc0806300053m4325104dx145cd8840c630453@mail.gmail.com>

```
On 2008-06-30 09:53:22 +0200, Sverre Rabbelier wrote:

> 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

```
