{"thread":{"id":"11432","subject":"[STGIT] stg refresh wish (splitting patches/removing files from a patch)","startedAt":"2007-12-30T19:03:33Z","lastAt":"2008-01-10T00:08:54Z","messageCount":7,"participants":["Peter Oberndorfer","Karl Hasselström"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"64235","messageId":"200712302003.33478.kumbayo84@arcor.de","threadId":"11432","inReplyTo":null,"subject":"[STGIT] stg refresh wish (splitting patches/removing files from a patch)","fromName":"Peter Oberndorfer","fromEmail":"kumbayo84@arcor.de","sentAt":"2007-12-30T19:03:33Z","receivedAt":"2007-12-30T19:03:33Z","isPatch":false,"sender":{"key":"kumbayo84@arcor.de","avatar":"https://avatars.githubusercontent.com/u/1041267?v=4"},"body":"Hi,\nI recently tried to split a stgit patch into 2 parts\nand it was not as easy as i would like it to be.\n\nHow do i exclude a file from a patch(use version of file present in HEAD^)\nwithout modifying the working dir?\n\nwith plain git i would use something like\ngit reset HEAD^ files_i_do_not_want_in_first_patch\ngit commit --amend\ngit add files_i_do_not_want_in_first_patch\ngit commit\n\nSo my idea was to add a --use-index [1] option to stg refresh\nWhen it is passed stg refresh will use the current index for the contenst of the refreshed patch \ninstead of looking at the working dir.\nThis would solve my problem[2] and also make it possible to use git-gui for \nstaging hunks.\n\nDo you think this would be a useful/good idea?\nOr do we want a separate command for removing files from a patch anyway?\n\nAnother thing that might be useful (in my scenario) would be a stg commit --top extension\nwhich commits at the top end of the stack\n(unfortunately this will loose the patch history for splitting commits)\nthen i can edit this commits without being afraid of confusing stgit\nand then stg assimilate /stg repair to make them managed by stg again\n\nGreetings Peter\n\n[1] rename by desire\n\n[2] new way for splitting a patch with extension\ngit reset HEAD^ files_i_do_not_want_in_first_patch\nstg refresh --use-index\nstg refresh -e\ngit add files_i_do_not_want_in_first_patch\nstg new\nstg refresh --use-index\n"},{"id":"64348","messageId":"200801022039.27611.kumbayo84@arcor.de","threadId":"11432","inReplyTo":"200712302003.33478.kumbayo84@arcor.de","subject":"[STG PATCH] refresh: add a --index option which takes the contents of the index as the new commit","fromName":"Peter Oberndorfer","fromEmail":"kumbayo84@arcor.de","sentAt":"2008-01-02T19:39:27Z","receivedAt":"2008-01-02T19:39:27Z","isPatch":true,"sender":{"key":"kumbayo84@arcor.de","avatar":"https://avatars.githubusercontent.com/u/1041267?v=4"},"body":"just like git commit would do without the -a option\n---\nOn Sonntag 30 Dezember 2007, Peter Oberndorfer wrote:\n> Hi,\n> I recently tried to split a stgit patch into 2 parts\n> and it was not as easy as i would like it to be.\n> \n> How do i exclude a file from a patch(use version of file present in HEAD^)\n> without modifying the working dir?\n> \n> with plain git i would use something like\n> git reset HEAD^ files_i_do_not_want_in_first_patch\n> git commit --amend\n> git add files_i_do_not_want_in_first_patch\n> git commit\n> \n> So my idea was to add a --use-index [1] option to stg refresh\n> When it is passed stg refresh will use the current index for the contenst of the refreshed patch \n> instead of looking at the working dir.\n> This would solve my problem[2] and also make it possible to use git-gui for \n> staging hunks.\n> \nOK, i got off my ass and hacked together the following patch\nbased on git://repo.or.cz/stgit/kha.git experimental\nAnd i used it to create and update this commit a few times :-)\nAdditionally it passes the (minimal) test i added.\nBut since i am not a stgit expert it is highly recommend that somebody else carefully\nlooks at the patch before going wild on real data.\n\n> Do you think this would be a useful/good idea?\n> Or do we want a separate command for removing files from a patch anyway?\nThe question is still open if this is useful for somebody else.\n\nGreetings Peter\n\nPS: i hope i put the right people on CC\n\n stgit/commands/refresh.py |   25 ++++++++++++++++---\n stgit/stack.py            |    6 ++++\n t/t2700-refresh.sh        |   57 ++++++++++++++++++++++++++++++++++++++++++++-\n 3 files changed, 83 insertions(+), 5 deletions(-)\n\ndiff --git a/stgit/commands/refresh.py b/stgit/commands/refresh.py\nindex 6e8ed0c..0420b98 100644\n--- a/stgit/commands/refresh.py\n+++ b/stgit/commands/refresh.py\n@@ -45,6 +45,9 @@ options = [make_option('-f', '--force',\n            make_option('--update',\n                        help = 'only update the current patch files',\n                        action = 'store_true'),\n+           make_option('--index',\n+                       help = 'use the current contents of the index instead of looking at the working directory',\n+                       action = 'store_true'),\n            make_option('--undo',\n                        help = 'revert the commit generated by the last refresh',\n                        action = 'store_true'),\n@@ -76,6 +79,14 @@ def func(parser, options, args):\n         if not patch:\n             raise CmdException, 'No patches applied'\n \n+    if options.index:\n+        if args or options.update:\n+            raise CmdException, \\\n+                  'Only full refresh is available with the --index option'\n+        if options.patch:\n+            raise CmdException, \\\n+                  '--patch is not (yet) compatible with --index option'\n+\n     if not options.force:\n         check_head_top_equal(crt_series)\n \n@@ -85,9 +96,10 @@ def func(parser, options, args):\n         out.done()\n         return\n \n-    files = [path for (stat, path) in git.tree_status(files = args, verbose = True)]\n+    if not options.index:\n+        files = [path for (stat, path) in git.tree_status(files = args, verbose = True)]\n \n-    if files or not crt_series.head_top_equal():\n+    if options.index or files or not crt_series.head_top_equal():\n         if options.patch:\n             applied = crt_series.get_applied()\n             between = applied[:applied.index(patch):-1]\n@@ -105,8 +117,13 @@ def func(parser, options, args):\n \n         if autoresolved == 'yes':\n             resolved_all()\n-        crt_series.refresh_patch(files = files,\n-                                 backup = True, notes = options.annotate)\n+\n+        if options.index:\n+            crt_series.refresh_patch(use_index = True,\n+                                     backup = True, notes = options.annotate)\n+        else:\n+            crt_series.refresh_patch(files = files,\n+                                     backup = True, notes = options.annotate)\n \n         if crt_series.empty_patch(patch):\n             out.done('empty patch')\ndiff --git a/stgit/stack.py b/stgit/stack.py\nindex 4203931..7d14261 100644\n--- a/stgit/stack.py\n+++ b/stgit/stack.py\n@@ -668,6 +668,7 @@ class Series(PatchSet):\n         config.remove_section('branch.%s.stgit' % self.get_name())\n \n     def refresh_patch(self, files = None, message = None, edit = False,\n+                      use_index = False,\n                       empty = False,\n                       show_patch = False,\n                       cache_update = True,\n@@ -717,6 +718,11 @@ class Series(PatchSet):\n         else:\n             tree_id = None\n \n+        if use_index:\n+            tree_id = None\n+            files = None\n+            cache_update = False\n+\n         commit_id = git.commit(files = files,\n                                message = descr, parents = [bottom],\n                                cache_update = cache_update,\ndiff --git a/t/t2700-refresh.sh b/t/t2700-refresh.sh\nindex 2e7901c..9eae85d 100755\n--- a/t/t2700-refresh.sh\n+++ b/t/t2700-refresh.sh\n@@ -6,8 +6,10 @@ test_description='Run \"stg refresh\"'\n \n test_expect_success 'Initialize StGit stack' '\n     stg init &&\n-    echo expected.txt >> .git/info/exclude &&\n+    echo expected*.txt >> .git/info/exclude &&\n     echo patches.txt >> .git/info/exclude &&\n+    echo show.txt >> .git/info/exclude &&\n+    echo diff.txt >> .git/info/exclude &&\n     stg new p0 -m \"base\" &&\n     for i in 1 2 3; do\n         echo base >> foo$i.txt &&\n@@ -62,4 +64,57 @@ test_expect_success 'Refresh bottom patch' '\n     diff -u expected.txt patches.txt\n '\n \n+cat > expected.txt <<EOF\n+p0\n+p1\n+p4\n+EOF\n+cat > expected2.txt <<EOF\n+diff --git a/foo1.txt b/foo1.txt\n+index 728535d..6f34984 100644\n+--- a/foo1.txt\n++++ b/foo1.txt\n+@@ -1,3 +1,4 @@\n+ base\n+ foo 1\n+ bar 1\n++baz 1\n+EOF\n+cat > expected3.txt <<EOF\n+diff --git a/foo1.txt b/foo1.txt\n+index 6f34984..a80eb63 100644\n+--- a/foo1.txt\n++++ b/foo1.txt\n+@@ -2,3 +2,4 @@ base\n+ foo 1\n+ bar 1\n+ baz 1\n++blah 1\n+diff --git a/foo2.txt b/foo2.txt\n+index 415c9f5..43168f2 100644\n+--- a/foo2.txt\n++++ b/foo2.txt\n+@@ -1,3 +1,4 @@\n+ base\n+ foo 2\n+ bar 2\n++baz 2\n+EOF\n+test_expect_success 'Refresh --index' '\n+    stg status &&\n+    stg new p4 -m \"refresh_index\" &&\n+    echo baz 1 >> foo1.txt &&\n+    git add foo1.txt &&\n+    echo blah 1 >> foo1.txt &&\n+    echo baz 2 >> foo2.txt &&\n+    stg refresh --index &&\n+    stg patches foo1.txt > patches.txt &&\n+    git diff HEAD^..HEAD > show.txt &&\n+    stg diff > diff.txt &&\n+    diff -u expected.txt patches.txt &&\n+    diff -u expected2.txt show.txt &&\n+    diff -u expected3.txt diff.txt &&\n+    stg new p5 -m \"cleanup again\" &&\n+    stg refresh\n+'\n test_done\n-- \n1.5.4.rc2\n"},{"id":"64644","messageId":"20080107105612.GA20981@diana.vm.bytemark.co.uk","threadId":"11432","inReplyTo":"200801022039.27611.kumbayo84@arcor.de","subject":"Re: [STG PATCH] refresh: add a --index option which takes the contents of the index as the new commit","fromName":"Karl Hasselström","fromEmail":"kha@treskal.com","sentAt":"2008-01-07T10:56:12Z","receivedAt":"2008-01-07T10:56:12Z","isPatch":true,"sender":{"key":"kha@treskal.com","avatar":"https://gravatar.com/avatar/f0120c734b5279b345075a28521e1ac66acb20c9913ffe9bf6ae97e53f7f3f13?d=mp&s=160"},"body":"On 2008-01-02 20:39:27 +0100, Peter Oberndorfer wrote:\n\n> On Sonntag 30 Dezember 2007, Peter Oberndorfer wrote:\n>\n> > Do you think this would be a useful/good idea? Or do we want a\n> > separate command for removing files from a patch anyway?\n>\n> The question is still open if this is useful for somebody else.\n\nI think it's a useful addition. Thanks!\n\n> diff --git a/stgit/stack.py b/stgit/stack.py\n> index 4203931..7d14261 100644\n> --- a/stgit/stack.py\n> +++ b/stgit/stack.py\n> @@ -668,6 +668,7 @@ class Series(PatchSet):\n>          config.remove_section('branch.%s.stgit' % self.get_name())\n>  \n>      def refresh_patch(self, files = None, message = None, edit = False,\n> +                      use_index = False,\n>                        empty = False,\n>                        show_patch = False,\n>                        cache_update = True,\n> @@ -717,6 +718,11 @@ class Series(PatchSet):\n>          else:\n>              tree_id = None\n>  \n> +        if use_index:\n> +            tree_id = None\n> +            files = None\n> +            cache_update = False\n> +\n>          commit_id = git.commit(files = files,\n>                                 message = descr, parents = [bottom],\n>                                 cache_update = cache_update,\n\nSo the use_index parameter to refresh_patch is actually not necessary?\nIn that case I'd rather you didn't add it, since the functions in\nstgit/stack.py have quite enough parameters already.\n\n> diff --git a/t/t2700-refresh.sh b/t/t2700-refresh.sh\n> index 2e7901c..9eae85d 100755\n> --- a/t/t2700-refresh.sh\n> +++ b/t/t2700-refresh.sh\n\nBonus points for adding a test case!\n\nI still haven't rebased my patch stack since Catalin accepted most of\nit just before Christmas. Once I've gotten around to that, I'll take\nyour patch -- hopefully by then updated to not add the exra argument\nto refresh_patch(). :-)\n\n-- \nKarl Hasselström, kha@treskal.com\n      www.treskal.com/kalle\n"},{"id":"64646","messageId":"20080107105943.GB20981@diana.vm.bytemark.co.uk","threadId":"11432","inReplyTo":"20080107105612.GA20981@diana.vm.bytemark.co.uk","subject":"Re: [STG PATCH] refresh: add a --index option which takes the contents of the index as the new commit","fromName":"Karl Hasselström","fromEmail":"kha@treskal.com","sentAt":"2008-01-07T10:59:43Z","receivedAt":"2008-01-07T10:59:43Z","isPatch":true,"sender":{"key":"kha@treskal.com","avatar":"https://gravatar.com/avatar/f0120c734b5279b345075a28521e1ac66acb20c9913ffe9bf6ae97e53f7f3f13?d=mp&s=160"},"body":"On 2008-01-07 11:56:12 +0100, Karl Hasselström wrote:\n\n> hopefully by then updated to not add the exra argument to\n> refresh_patch(). :-)\n\nAnd with a sign-off, too, please.\n\n-- \nKarl Hasselström, kha@treskal.com\n      www.treskal.com/kalle\n"},{"id":"64777","messageId":"200801082142.47060.kumbayo84@arcor.de","threadId":"11432","inReplyTo":"20080107105612.GA20981@diana.vm.bytemark.co.uk","subject":"[STG PATCH] add a --index option to refresh which takes the contents of the index as the new commit","fromName":"Peter Oberndorfer","fromEmail":"kumbayo84@arcor.de","sentAt":"2008-01-08T20:42:46Z","receivedAt":"2008-01-08T20:42:46Z","isPatch":true,"sender":{"key":"kumbayo84@arcor.de","avatar":"https://avatars.githubusercontent.com/u/1041267?v=4"},"body":"\nThis allows to stage only certain changes to a file by only adding\nthe desired parts to the index with git-gui, ugit, git add -i or another tool\nthat manipulates the index and then run stg refresh --index\nit also allows removing a file from a patch by running git reset HEAD^ -- file_to_remove\nfollowed by a stg refresh --index\n\nSigned-off-by: Peter Oberndorfer <kumbayo84@arcor.de>\n---\n\nOn Montag 07 Januar 2008, Karl Hasselström wrote:\n> On 2008-01-02 20:39:27 +0100, Peter Oberndorfer wrote:\n> \n> > On Sonntag 30 Dezember 2007, Peter Oberndorfer wrote:\n> >\n> > > Do you think this would be a useful/good idea? Or do we want a\n> > > separate command for removing files from a patch anyway?\n> >\n> > The question is still open if this is useful for somebody else.\n> \n> I think it's a useful addition. Thanks!\nGood since it was useful for me too even while writing this patch :-)\n\n> So the use_index parameter to refresh_patch is actually not necessary?\n> In that case I'd rather you didn't add it, since the functions in\n> stgit/stack.py have quite enough parameters already.\n> \nIn the beginning i was afraid it would be to obscure to call it this way\nwith all parameters set to some specific values.\nBut having more parameters does not make it better :-)\nDone\n> > diff --git a/t/t2700-refresh.sh b/t/t2700-refresh.sh\n> > index 2e7901c..9eae85d 100755\n> > --- a/t/t2700-refresh.sh\n> > +++ b/t/t2700-refresh.sh\n> \n> Bonus points for adding a test case!\n> \n> I still haven't rebased my patch stack since Catalin accepted most of\n> it just before Christmas. Once I've gotten around to that, I'll take\n> your patch -- hopefully by then updated to not add the exra argument\n> to refresh_patch(). :-)\n> \n\nPatch now comes with a Signed-off-by and a log message that explains\nhow this feature could be used.\nIt was tested with the testcase, used during development of this patch\nand on another repo, but still take care when using it :-)\n\n stgit/commands/refresh.py |   25 ++++++++++++++++---\n t/t2700-refresh.sh        |   57 ++++++++++++++++++++++++++++++++++++++++++++-\n 2 files changed, 77 insertions(+), 5 deletions(-)\n\ndiff --git a/stgit/commands/refresh.py b/stgit/commands/refresh.py\nindex 6e8ed0c..952b1b6 100644\n--- a/stgit/commands/refresh.py\n+++ b/stgit/commands/refresh.py\n@@ -45,6 +45,9 @@ options = [make_option('-f', '--force',\n            make_option('--update',\n                        help = 'only update the current patch files',\n                        action = 'store_true'),\n+           make_option('--index',\n+                       help = 'use the current contents of the index instead of looking at the working directory',\n+                       action = 'store_true'),\n            make_option('--undo',\n                        help = 'revert the commit generated by the last refresh',\n                        action = 'store_true'),\n@@ -76,6 +79,14 @@ def func(parser, options, args):\n         if not patch:\n             raise CmdException, 'No patches applied'\n \n+    if options.index:\n+        if args or options.update:\n+            raise CmdException, \\\n+                  'Only full refresh is available with the --index option'\n+        if options.patch:\n+            raise CmdException, \\\n+                  '--patch is not compatible with the --index option'\n+\n     if not options.force:\n         check_head_top_equal(crt_series)\n \n@@ -85,9 +96,10 @@ def func(parser, options, args):\n         out.done()\n         return\n \n-    files = [path for (stat, path) in git.tree_status(files = args, verbose = True)]\n+    if not options.index:\n+        files = [path for (stat, path) in git.tree_status(files = args, verbose = True)]\n \n-    if files or not crt_series.head_top_equal():\n+    if options.index or files or not crt_series.head_top_equal():\n         if options.patch:\n             applied = crt_series.get_applied()\n             between = applied[:applied.index(patch):-1]\n@@ -105,8 +117,13 @@ def func(parser, options, args):\n \n         if autoresolved == 'yes':\n             resolved_all()\n-        crt_series.refresh_patch(files = files,\n-                                 backup = True, notes = options.annotate)\n+\n+        if options.index:\n+            crt_series.refresh_patch(cache_update = False,\n+                                     backup = True, notes = options.annotate)\n+        else:\n+            crt_series.refresh_patch(files = files,\n+                                     backup = True, notes = options.annotate)\n \n         if crt_series.empty_patch(patch):\n             out.done('empty patch')\ndiff --git a/t/t2700-refresh.sh b/t/t2700-refresh.sh\nindex 2e7901c..9eae85d 100755\n--- a/t/t2700-refresh.sh\n+++ b/t/t2700-refresh.sh\n@@ -6,8 +6,10 @@ test_description='Run \"stg refresh\"'\n \n test_expect_success 'Initialize StGit stack' '\n     stg init &&\n-    echo expected.txt >> .git/info/exclude &&\n+    echo expected*.txt >> .git/info/exclude &&\n     echo patches.txt >> .git/info/exclude &&\n+    echo show.txt >> .git/info/exclude &&\n+    echo diff.txt >> .git/info/exclude &&\n     stg new p0 -m \"base\" &&\n     for i in 1 2 3; do\n         echo base >> foo$i.txt &&\n@@ -62,4 +64,57 @@ test_expect_success 'Refresh bottom patch' '\n     diff -u expected.txt patches.txt\n '\n \n+cat > expected.txt <<EOF\n+p0\n+p1\n+p4\n+EOF\n+cat > expected2.txt <<EOF\n+diff --git a/foo1.txt b/foo1.txt\n+index 728535d..6f34984 100644\n+--- a/foo1.txt\n++++ b/foo1.txt\n+@@ -1,3 +1,4 @@\n+ base\n+ foo 1\n+ bar 1\n++baz 1\n+EOF\n+cat > expected3.txt <<EOF\n+diff --git a/foo1.txt b/foo1.txt\n+index 6f34984..a80eb63 100644\n+--- a/foo1.txt\n++++ b/foo1.txt\n+@@ -2,3 +2,4 @@ base\n+ foo 1\n+ bar 1\n+ baz 1\n++blah 1\n+diff --git a/foo2.txt b/foo2.txt\n+index 415c9f5..43168f2 100644\n+--- a/foo2.txt\n++++ b/foo2.txt\n+@@ -1,3 +1,4 @@\n+ base\n+ foo 2\n+ bar 2\n++baz 2\n+EOF\n+test_expect_success 'Refresh --index' '\n+    stg status &&\n+    stg new p4 -m \"refresh_index\" &&\n+    echo baz 1 >> foo1.txt &&\n+    git add foo1.txt &&\n+    echo blah 1 >> foo1.txt &&\n+    echo baz 2 >> foo2.txt &&\n+    stg refresh --index &&\n+    stg patches foo1.txt > patches.txt &&\n+    git diff HEAD^..HEAD > show.txt &&\n+    stg diff > diff.txt &&\n+    diff -u expected.txt patches.txt &&\n+    diff -u expected2.txt show.txt &&\n+    diff -u expected3.txt diff.txt &&\n+    stg new p5 -m \"cleanup again\" &&\n+    stg refresh\n+'\n test_done\n-- \n1.5.4.rc2\n"},{"id":"64828","messageId":"20080109072358.GB28839@diana.vm.bytemark.co.uk","threadId":"11432","inReplyTo":"200801082142.47060.kumbayo84@arcor.de","subject":"Re: [STG PATCH] add a --index option to refresh which takes the contents of the index as the new commit","fromName":"Karl Hasselström","fromEmail":"kha@treskal.com","sentAt":"2008-01-09T07:23:58Z","receivedAt":"2008-01-09T07:23:58Z","isPatch":true,"sender":{"key":"kha@treskal.com","avatar":"https://gravatar.com/avatar/f0120c734b5279b345075a28521e1ac66acb20c9913ffe9bf6ae97e53f7f3f13?d=mp&s=160"},"body":"On 2008-01-08 21:42:46 +0100, Peter Oberndorfer wrote:\n\n> On Montag 07 Januar 2008, Karl Hasselström wrote:\n>\n> > So the use_index parameter to refresh_patch is actually not\n> > necessary? In that case I'd rather you didn't add it, since the\n> > functions in stgit/stack.py have quite enough parameters already.\n>\n> In the beginning i was afraid it would be to obscure to call it this\n> way with all parameters set to some specific values. But having more\n> parameters does not make it better :-) Done\n\nThanks.\n\n> Patch now comes with a Signed-off-by and a log message that explains\n> how this feature could be used. It was tested with the testcase,\n> used during development of this patch and on another repo, but still\n> take care when using it :-)\n\nI may be promising too much now, but hopefully I'll get to this\ntonight.\n\n-- \nKarl Hasselström, kha@treskal.com\n      www.treskal.com/kalle\n"},{"id":"64890","messageId":"20080110000854.GA13111@diana.vm.bytemark.co.uk","threadId":"11432","inReplyTo":"20080109072358.GB28839@diana.vm.bytemark.co.uk","subject":"Re: [STG PATCH] add a --index option to refresh which takes the contents of the index as the new commit","fromName":"Karl Hasselström","fromEmail":"kha@treskal.com","sentAt":"2008-01-10T00:08:54Z","receivedAt":"2008-01-10T00:08:54Z","isPatch":true,"sender":{"key":"kha@treskal.com","avatar":"https://gravatar.com/avatar/f0120c734b5279b345075a28521e1ac66acb20c9913ffe9bf6ae97e53f7f3f13?d=mp&s=160"},"body":"On 2008-01-09 08:23:58 +0100, Karl Hasselström wrote:\n\n> On 2008-01-08 21:42:46 +0100, Peter Oberndorfer wrote:\n>\n> > Patch now comes with a Signed-off-by and a log message that\n> > explains how this feature could be used. It was tested with the\n> > testcase, used during development of this patch and on another\n> > repo, but still take care when using it :-)\n>\n> I may be promising too much now, but hopefully I'll get to this\n> tonight.\n\nI've rebased my patch stack on top of Catalin's master now, and put\nyour two patches on top. The --index patch is only in experimental and\nnot stable, since you recommend further testing.\n\nI massaged the commit messages slightly, mainly to get a reasonably\nshort first line and end all sentences with a period (except on the\nfirst line, of course!).\n\n-- \nKarl Hasselström, kha@treskal.com\n      www.treskal.com/kalle\n"}]}