# [StGit PATCH] Check for local changes with "goto"

3 messages from 2009-01-14 to 2009-01-15. Participants: Catalin Marinas, Karl Hasselström.
Thread: https://gitlist.dev/t/17180

## Catalin Marinas, 2009-01-14 22:59

Subject: [StGit PATCH] Check for local changes with "goto"
Message-ID: <20090114225945.11098.88671.stgit@localhost.localdomain>
URL: https://gitlist.dev/e/20090114225945.11098.88671.stgit%40localhost.localdomain

```
This is done by default, unless the --keep option is passed, for
consistency with the "pop" command.

Signed-off-by: Catalin Marinas <catalin.marinas@gmail.com>
---
 stgit/commands/common.py  |    7 +++++++
 stgit/commands/goto.py    |    8 +++++++-
 t/t2300-refresh-subdir.sh |    2 +-
 t/t2800-goto-subdir.sh    |    4 ++--
 t/t3000-dirty-merge.sh    |    2 +-
 5 files changed, 18 insertions(+), 5 deletions(-)

diff --git a/stgit/commands/common.py b/stgit/commands/common.py
index 6bb3685..8ae43ff 100644
--- a/stgit/commands/common.py
+++ b/stgit/commands/common.py
@@ -100,6 +100,13 @@ def check_conflicts():
                            ' then use "resolve <files>" or revert the'
                            ' changes with "status --reset".')
 
+def check_clean(repository):
+    """Check whether the index is up to date.
+    """
+    if not repository.default_index.is_clean():
+        raise CmdException('Repository not clean. Use "refresh" or '
+                           '"status --reset"')
+
 def print_crt_patch(crt_series, branch = None):
     if not branch:
         patch = crt_series.get_current()
diff --git a/stgit/commands/goto.py b/stgit/commands/goto.py
index 60a917e..6483011 100644
--- a/stgit/commands/goto.py
+++ b/stgit/commands/goto.py
@@ -18,6 +18,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 from stgit.commands import common
 from stgit.lib import transaction
 from stgit import argparse
+from stgit.argparse import opt
 
 help = 'Push or pop patches to the given one'
 kind = 'stack'
@@ -27,7 +28,10 @@ Push/pop patches to/from the stack until the one given on the command
 line becomes current."""
 
 args = [argparse.other_applied_patches, argparse.unapplied_patches]
-options = []
+options = [
+    opt('-k', '--keep', action = 'store_true',
+        short = 'Keep the local changes')
+]
 
 directory = common.DirectoryHasRepositoryLib()
 
@@ -38,6 +42,8 @@ def func(parser, options, args):
 
     stack = directory.repository.current_stack
     iw = stack.repository.default_iw
+    if not options.keep:
+        common.check_clean(directory.repository)
     trans = transaction.StackTransaction(stack, 'goto')
     if patch in trans.applied:
         to_pop = set(trans.applied[trans.applied.index(patch)+1:])
diff --git a/t/t2300-refresh-subdir.sh b/t/t2300-refresh-subdir.sh
index d731a11..89c95db 100755
--- a/t/t2300-refresh-subdir.sh
+++ b/t/t2300-refresh-subdir.sh
@@ -65,7 +65,7 @@ test_expect_success 'refresh -u -p <subdir>' '
 
 test_expect_success 'refresh an unapplied patch' '
     stg refresh -u &&
-    stg goto p0 &&
+    stg goto --keep p0 &&
     test "$(stg status)" = "M foo.txt" &&
     stg refresh -p p1 &&
     test "$(stg status)" = "" &&
diff --git a/t/t2800-goto-subdir.sh b/t/t2800-goto-subdir.sh
index 28b8292..855972b 100755
--- a/t/t2800-goto-subdir.sh
+++ b/t/t2800-goto-subdir.sh
@@ -25,7 +25,7 @@ cat > expected2.txt <<EOF
 bar
 EOF
 test_expect_success 'Goto in subdirectory (just pop)' '
-    (cd foo && stg goto p1) &&
+    (cd foo && stg goto --keep p1) &&
     cat foo/bar > actual.txt &&
     test_cmp expected1.txt actual.txt &&
     ls foo > actual.txt &&
@@ -48,7 +48,7 @@ cat > expected2.txt <<EOF
 bar
 EOF
 test_expect_success 'Goto in subdirectory (conflicting push)' '
-    (cd foo && stg goto p3) ;
+    (cd foo && stg goto --keep p3) ;
     [ $? -eq 3 ] &&
     cat foo/bar > actual.txt &&
     test_cmp expected1.txt actual.txt &&
diff --git a/t/t3000-dirty-merge.sh b/t/t3000-dirty-merge.sh
index f0f79d5..419d86e 100755
--- a/t/t3000-dirty-merge.sh
+++ b/t/t3000-dirty-merge.sh
@@ -26,7 +26,7 @@ test_expect_success 'Push with dirty worktree' '
     echo 4 > a &&
     [ "$(echo $(stg series --applied --noprefix))" = "p1" ] &&
     [ "$(echo $(stg series --unapplied --noprefix))" = "p2" ] &&
-    conflict stg goto p2 &&
+    conflict stg goto --keep p2 &&
     [ "$(echo $(stg series --applied --noprefix))" = "p1" ] &&
     [ "$(echo $(stg series --unapplied --noprefix))" = "p2" ] &&
     [ "$(echo $(cat a))" = "4" ]

```

## Karl Hasselström, 2009-01-15 08:37

Subject: Re: [StGit PATCH] Check for local changes with "goto"
Message-ID: <20090115083700.GB24890@diana.vm.bytemark.co.uk>
URL: https://gitlist.dev/e/20090115083700.GB24890%40diana.vm.bytemark.co.uk
In-Reply-To: <20090114225945.11098.88671.stgit@localhost.localdomain>

```
I'm not opposed to the change as such (even if I personally think it's
very convenient to allow operations like goto if the local changes
don't touch the same files), but ...

On 2009-01-14 22:59:45 +0000, Catalin Marinas wrote:

>  stgit/commands/common.py  |    7 +++++++
>  stgit/commands/goto.py    |    8 +++++++-

... are you sure it wouldn't be better to build the check into
transaction.py, so that all new-infrastructure command would share it?

-- 
Karl Hasselström, kha@treskal.com
      www.treskal.com/kalle

```

## Catalin Marinas, 2009-01-15 22:24

Subject: Re: [StGit PATCH] Check for local changes with "goto"
Message-ID: <b0943d9e0901151424m49f6869cq1255cf841703dc9d@mail.gmail.com>
URL: https://gitlist.dev/e/b0943d9e0901151424m49f6869cq1255cf841703dc9d%40mail.gmail.com
In-Reply-To: <20090115083700.GB24890@diana.vm.bytemark.co.uk>

```
2009/1/15 Karl Hasselström <kha@treskal.com>:
> I'm not opposed to the change as such (even if I personally think it's
> very convenient to allow operations like goto if the local changes
> don't touch the same files), but ...

That would work if "refresh" only commits files previously added to
the patch (the same way as quilt). I found myself many times moving to
another patch and refreshing more than I wanted to add to that patch
because I forgot to run "status" before "goto".

Maybe we can make this configurable to accommodate both variants
(would be even easier if I move the check to transaction.py).

> On 2009-01-14 22:59:45 +0000, Catalin Marinas wrote:
>
>>  stgit/commands/common.py  |    7 +++++++
>>  stgit/commands/goto.py    |    8 +++++++-
>
> ... are you sure it wouldn't be better to build the check into
> transaction.py, so that all new-infrastructure command would share it?

OK, I'll do this and repost.

-- 
Catalin

```
