public inbox for git@vger.kernel.org 
 help / color / mirror / Atom feed
From: Peter Oberndorfer <kumbayo84@arcor•de>
To: "Karl Hasselström" <kha@treskal•com>
Cc: Git Mailing List <git@vger•kernel.org>,
	Catalin Marinas <catalin.marinas@gmail•com>
Subject: [STG PATCH] add a --index option to refresh which takes the contents of the index as the new commit
Date: Tue, 8 Jan 2008 21:42:46 +0100	[thread overview]
Message-ID: <200801082142.47060.kumbayo84@arcor.de> (raw)
In-Reply-To: <20080107105612.GA20981@diana.vm.bytemark.co.uk>


This allows to stage only certain changes to a file by only adding
the desired parts to the index with git-gui, ugit, git add -i or another tool
that manipulates the index and then run stg refresh --index
it also allows removing a file from a patch by running git reset HEAD^ -- file_to_remove
followed by a stg refresh --index

Signed-off-by: Peter Oberndorfer <kumbayo84@arcor•de>
---

On Montag 07 Januar 2008, Karl Hasselström wrote:
> On 2008-01-02 20:39:27 +0100, Peter Oberndorfer wrote:
> 
> > On Sonntag 30 Dezember 2007, Peter Oberndorfer wrote:
> >
> > > Do you think this would be a useful/good idea? Or do we want a
> > > separate command for removing files from a patch anyway?
> >
> > The question is still open if this is useful for somebody else.
> 
> I think it's a useful addition. Thanks!
Good since it was useful for me too even while writing this patch :-)

> So the use_index parameter to refresh_patch is actually not necessary?
> In that case I'd rather you didn't add it, since the functions in
> stgit/stack.py have quite enough parameters already.
> 
In the beginning i was afraid it would be to obscure to call it this way
with all parameters set to some specific values.
But having more parameters does not make it better :-)
Done
> > diff --git a/t/t2700-refresh.sh b/t/t2700-refresh.sh
> > index 2e7901c..9eae85d 100755
> > --- a/t/t2700-refresh.sh
> > +++ b/t/t2700-refresh.sh
> 
> Bonus points for adding a test case!
> 
> I still haven't rebased my patch stack since Catalin accepted most of
> it just before Christmas. Once I've gotten around to that, I'll take
> your patch -- hopefully by then updated to not add the exra argument
> to refresh_patch(). :-)
> 

Patch now comes with a Signed-off-by and a log message that explains
how this feature could be used.
It was tested with the testcase, used during development of this patch
and on another repo, but still take care when using it :-)

 stgit/commands/refresh.py |   25 ++++++++++++++++---
 t/t2700-refresh.sh        |   57 ++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 77 insertions(+), 5 deletions(-)

diff --git a/stgit/commands/refresh.py b/stgit/commands/refresh.py
index 6e8ed0c..952b1b6 100644
--- a/stgit/commands/refresh.py
+++ b/stgit/commands/refresh.py
@@ -45,6 +45,9 @@ options = [make_option('-f', '--force',
            make_option('--update',
                        help = 'only update the current patch files',
                        action = 'store_true'),
+           make_option('--index',
+                       help = 'use the current contents of the index instead of looking at the working directory',
+                       action = 'store_true'),
            make_option('--undo',
                        help = 'revert the commit generated by the last refresh',
                        action = 'store_true'),
@@ -76,6 +79,14 @@ def func(parser, options, args):
         if not patch:
             raise CmdException, 'No patches applied'
 
+    if options.index:
+        if args or options.update:
+            raise CmdException, \
+                  'Only full refresh is available with the --index option'
+        if options.patch:
+            raise CmdException, \
+                  '--patch is not compatible with the --index option'
+
     if not options.force:
         check_head_top_equal(crt_series)
 
@@ -85,9 +96,10 @@ def func(parser, options, args):
         out.done()
         return
 
-    files = [path for (stat, path) in git.tree_status(files = args, verbose = True)]
+    if not options.index:
+        files = [path for (stat, path) in git.tree_status(files = args, verbose = True)]
 
-    if files or not crt_series.head_top_equal():
+    if options.index or files or not crt_series.head_top_equal():
         if options.patch:
             applied = crt_series.get_applied()
             between = applied[:applied.index(patch):-1]
@@ -105,8 +117,13 @@ def func(parser, options, args):
 
         if autoresolved == 'yes':
             resolved_all()
-        crt_series.refresh_patch(files = files,
-                                 backup = True, notes = options.annotate)
+
+        if options.index:
+            crt_series.refresh_patch(cache_update = False,
+                                     backup = True, notes = options.annotate)
+        else:
+            crt_series.refresh_patch(files = files,
+                                     backup = True, notes = options.annotate)
 
         if crt_series.empty_patch(patch):
             out.done('empty patch')
diff --git a/t/t2700-refresh.sh b/t/t2700-refresh.sh
index 2e7901c..9eae85d 100755
--- a/t/t2700-refresh.sh
+++ b/t/t2700-refresh.sh
@@ -6,8 +6,10 @@ test_description='Run "stg refresh"'
 
 test_expect_success 'Initialize StGit stack' '
     stg init &&
-    echo expected.txt >> .git/info/exclude &&
+    echo expected*.txt >> .git/info/exclude &&
     echo patches.txt >> .git/info/exclude &&
+    echo show.txt >> .git/info/exclude &&
+    echo diff.txt >> .git/info/exclude &&
     stg new p0 -m "base" &&
     for i in 1 2 3; do
         echo base >> foo$i.txt &&
@@ -62,4 +64,57 @@ test_expect_success 'Refresh bottom patch' '
     diff -u expected.txt patches.txt
 '
 
+cat > expected.txt <<EOF
+p0
+p1
+p4
+EOF
+cat > expected2.txt <<EOF
+diff --git a/foo1.txt b/foo1.txt
+index 728535d..6f34984 100644
+--- a/foo1.txt
++++ b/foo1.txt
+@@ -1,3 +1,4 @@
+ base
+ foo 1
+ bar 1
++baz 1
+EOF
+cat > expected3.txt <<EOF
+diff --git a/foo1.txt b/foo1.txt
+index 6f34984..a80eb63 100644
+--- a/foo1.txt
++++ b/foo1.txt
+@@ -2,3 +2,4 @@ base
+ foo 1
+ bar 1
+ baz 1
++blah 1
+diff --git a/foo2.txt b/foo2.txt
+index 415c9f5..43168f2 100644
+--- a/foo2.txt
++++ b/foo2.txt
+@@ -1,3 +1,4 @@
+ base
+ foo 2
+ bar 2
++baz 2
+EOF
+test_expect_success 'Refresh --index' '
+    stg status &&
+    stg new p4 -m "refresh_index" &&
+    echo baz 1 >> foo1.txt &&
+    git add foo1.txt &&
+    echo blah 1 >> foo1.txt &&
+    echo baz 2 >> foo2.txt &&
+    stg refresh --index &&
+    stg patches foo1.txt > patches.txt &&
+    git diff HEAD^..HEAD > show.txt &&
+    stg diff > diff.txt &&
+    diff -u expected.txt patches.txt &&
+    diff -u expected2.txt show.txt &&
+    diff -u expected3.txt diff.txt &&
+    stg new p5 -m "cleanup again" &&
+    stg refresh
+'
 test_done
-- 
1.5.4.rc2

  parent reply	other threads:[~2008-01-08 20:42 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-12-30 19:03 [STGIT] stg refresh wish (splitting patches/removing files from a patch) Peter Oberndorfer
2008-01-02 19:39 ` [STG PATCH] refresh: add a --index option which takes the contents of the index as the new commit Peter Oberndorfer
2008-01-07 10:56   ` Karl Hasselström
2008-01-07 10:59     ` Karl Hasselström
2008-01-08 20:42     ` Peter Oberndorfer [this message]
2008-01-09  7:23       ` [STG PATCH] add a --index option to refresh " Karl Hasselström
2008-01-10  0:08         ` Karl Hasselström

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200801082142.47060.kumbayo84@arcor.de \
    --to=kumbayo84@arcor$(echo .)de \
    --cc=catalin.marinas@gmail$(echo .)com \
    --cc=git@vger$(echo .)kernel.org \
    --cc=kha@treskal$(echo .)com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox