{"thread":{"id":"17180","subject":"[StGit PATCH] Check for local changes with \"goto\"","startedAt":"2009-01-14T22:59:45Z","lastAt":"2009-01-15T22:24:53Z","messageCount":3,"participants":["Catalin Marinas","Karl Hasselström"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"100503","messageId":"20090114225945.11098.88671.stgit@localhost.localdomain","threadId":"17180","inReplyTo":null,"subject":"[StGit PATCH] Check for local changes with \"goto\"","fromName":"Catalin Marinas","fromEmail":"catalin.marinas@gmail.com","sentAt":"2009-01-14T22:59:45Z","receivedAt":"2009-01-14T22:59:45Z","isPatch":true,"sender":{"key":"catalin.marinas@gmail.com","avatar":null},"body":"This is done by default, unless the --keep option is passed, for\nconsistency with the \"pop\" command.\n\nSigned-off-by: Catalin Marinas <catalin.marinas@gmail.com>\n---\n stgit/commands/common.py  |    7 +++++++\n stgit/commands/goto.py    |    8 +++++++-\n t/t2300-refresh-subdir.sh |    2 +-\n t/t2800-goto-subdir.sh    |    4 ++--\n t/t3000-dirty-merge.sh    |    2 +-\n 5 files changed, 18 insertions(+), 5 deletions(-)\n\ndiff --git a/stgit/commands/common.py b/stgit/commands/common.py\nindex 6bb3685..8ae43ff 100644\n--- a/stgit/commands/common.py\n+++ b/stgit/commands/common.py\n@@ -100,6 +100,13 @@ def check_conflicts():\n                            ' then use \"resolve <files>\" or revert the'\n                            ' changes with \"status --reset\".')\n \n+def check_clean(repository):\n+    \"\"\"Check whether the index is up to date.\n+    \"\"\"\n+    if not repository.default_index.is_clean():\n+        raise CmdException('Repository not clean. Use \"refresh\" or '\n+                           '\"status --reset\"')\n+\n def print_crt_patch(crt_series, branch = None):\n     if not branch:\n         patch = crt_series.get_current()\ndiff --git a/stgit/commands/goto.py b/stgit/commands/goto.py\nindex 60a917e..6483011 100644\n--- a/stgit/commands/goto.py\n+++ b/stgit/commands/goto.py\n@@ -18,6 +18,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\n from stgit.commands import common\n from stgit.lib import transaction\n from stgit import argparse\n+from stgit.argparse import opt\n \n help = 'Push or pop patches to the given one'\n kind = 'stack'\n@@ -27,7 +28,10 @@ Push/pop patches to/from the stack until the one given on the command\n line becomes current.\"\"\"\n \n args = [argparse.other_applied_patches, argparse.unapplied_patches]\n-options = []\n+options = [\n+    opt('-k', '--keep', action = 'store_true',\n+        short = 'Keep the local changes')\n+]\n \n directory = common.DirectoryHasRepositoryLib()\n \n@@ -38,6 +42,8 @@ def func(parser, options, args):\n \n     stack = directory.repository.current_stack\n     iw = stack.repository.default_iw\n+    if not options.keep:\n+        common.check_clean(directory.repository)\n     trans = transaction.StackTransaction(stack, 'goto')\n     if patch in trans.applied:\n         to_pop = set(trans.applied[trans.applied.index(patch)+1:])\ndiff --git a/t/t2300-refresh-subdir.sh b/t/t2300-refresh-subdir.sh\nindex d731a11..89c95db 100755\n--- a/t/t2300-refresh-subdir.sh\n+++ b/t/t2300-refresh-subdir.sh\n@@ -65,7 +65,7 @@ test_expect_success 'refresh -u -p <subdir>' '\n \n test_expect_success 'refresh an unapplied patch' '\n     stg refresh -u &&\n-    stg goto p0 &&\n+    stg goto --keep p0 &&\n     test \"$(stg status)\" = \"M foo.txt\" &&\n     stg refresh -p p1 &&\n     test \"$(stg status)\" = \"\" &&\ndiff --git a/t/t2800-goto-subdir.sh b/t/t2800-goto-subdir.sh\nindex 28b8292..855972b 100755\n--- a/t/t2800-goto-subdir.sh\n+++ b/t/t2800-goto-subdir.sh\n@@ -25,7 +25,7 @@ cat > expected2.txt <<EOF\n bar\n EOF\n test_expect_success 'Goto in subdirectory (just pop)' '\n-    (cd foo && stg goto p1) &&\n+    (cd foo && stg goto --keep p1) &&\n     cat foo/bar > actual.txt &&\n     test_cmp expected1.txt actual.txt &&\n     ls foo > actual.txt &&\n@@ -48,7 +48,7 @@ cat > expected2.txt <<EOF\n bar\n EOF\n test_expect_success 'Goto in subdirectory (conflicting push)' '\n-    (cd foo && stg goto p3) ;\n+    (cd foo && stg goto --keep p3) ;\n     [ $? -eq 3 ] &&\n     cat foo/bar > actual.txt &&\n     test_cmp expected1.txt actual.txt &&\ndiff --git a/t/t3000-dirty-merge.sh b/t/t3000-dirty-merge.sh\nindex f0f79d5..419d86e 100755\n--- a/t/t3000-dirty-merge.sh\n+++ b/t/t3000-dirty-merge.sh\n@@ -26,7 +26,7 @@ test_expect_success 'Push with dirty worktree' '\n     echo 4 > a &&\n     [ \"$(echo $(stg series --applied --noprefix))\" = \"p1\" ] &&\n     [ \"$(echo $(stg series --unapplied --noprefix))\" = \"p2\" ] &&\n-    conflict stg goto p2 &&\n+    conflict stg goto --keep p2 &&\n     [ \"$(echo $(stg series --applied --noprefix))\" = \"p1\" ] &&\n     [ \"$(echo $(stg series --unapplied --noprefix))\" = \"p2\" ] &&\n     [ \"$(echo $(cat a))\" = \"4\" ]\n"},{"id":"100552","messageId":"20090115083700.GB24890@diana.vm.bytemark.co.uk","threadId":"17180","inReplyTo":"20090114225945.11098.88671.stgit@localhost.localdomain","subject":"Re: [StGit PATCH] Check for local changes with \"goto\"","fromName":"Karl Hasselström","fromEmail":"kha@treskal.com","sentAt":"2009-01-15T08:37:00Z","receivedAt":"2009-01-15T08:37:00Z","isPatch":true,"sender":{"key":"kha@treskal.com","avatar":"https://gravatar.com/avatar/f0120c734b5279b345075a28521e1ac66acb20c9913ffe9bf6ae97e53f7f3f13?d=mp&s=160"},"body":"I'm not opposed to the change as such (even if I personally think it's\nvery convenient to allow operations like goto if the local changes\ndon't touch the same files), but ...\n\nOn 2009-01-14 22:59:45 +0000, Catalin Marinas wrote:\n\n>  stgit/commands/common.py  |    7 +++++++\n>  stgit/commands/goto.py    |    8 +++++++-\n\n... are you sure it wouldn't be better to build the check into\ntransaction.py, so that all new-infrastructure command would share it?\n\n-- \nKarl Hasselström, kha@treskal.com\n      www.treskal.com/kalle\n"},{"id":"100665","messageId":"b0943d9e0901151424m49f6869cq1255cf841703dc9d@mail.gmail.com","threadId":"17180","inReplyTo":"20090115083700.GB24890@diana.vm.bytemark.co.uk","subject":"Re: [StGit PATCH] Check for local changes with \"goto\"","fromName":"Catalin Marinas","fromEmail":"catalin.marinas@gmail.com","sentAt":"2009-01-15T22:24:53Z","receivedAt":"2009-01-15T22:24:53Z","isPatch":true,"sender":{"key":"catalin.marinas@gmail.com","avatar":null},"body":"2009/1/15 Karl Hasselström <kha@treskal.com>:\n> I'm not opposed to the change as such (even if I personally think it's\n> very convenient to allow operations like goto if the local changes\n> don't touch the same files), but ...\n\nThat would work if \"refresh\" only commits files previously added to\nthe patch (the same way as quilt). I found myself many times moving to\nanother patch and refreshing more than I wanted to add to that patch\nbecause I forgot to run \"status\" before \"goto\".\n\nMaybe we can make this configurable to accommodate both variants\n(would be even easier if I move the check to transaction.py).\n\n> On 2009-01-14 22:59:45 +0000, Catalin Marinas wrote:\n>\n>>  stgit/commands/common.py  |    7 +++++++\n>>  stgit/commands/goto.py    |    8 +++++++-\n>\n> ... are you sure it wouldn't be better to build the check into\n> transaction.py, so that all new-infrastructure command would share it?\n\nOK, I'll do this and repost.\n\n-- \nCatalin\n"}]}