# [StGit PATCH] Add --file option to pick

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

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

Subject: [StGit PATCH] Add --file option to pick
Message-ID: <20090114225930.11098.2144.stgit@localhost.localdomain>
URL: https://gitlist.dev/e/20090114225930.11098.2144.stgit%40localhost.localdomain

```
This allows folding of specific files only.

Signed-off-by: Catalin Marinas <catalin.marinas@gmail.com>
---
 stgit/commands/pick.py |   12 ++++++++++--
 1 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/stgit/commands/pick.py b/stgit/commands/pick.py
index ee08c01..b0e9114 100644
--- a/stgit/commands/pick.py
+++ b/stgit/commands/pick.py
@@ -52,6 +52,8 @@ options = [
         short = 'Fold the commit object into the current patch'),
     opt('--update', action = 'store_true',
         short = 'Like fold but only update the current patch files'),
+    opt('-f', '--files', action = 'append',
+        short = 'Only fold the given files'),
     opt('--unapplied', action = 'store_true',
         short = 'Keep the patch unapplied')]
 
@@ -83,8 +85,11 @@ def __pick_commit(commit_id, patchname, options):
         out.start('Folding commit %s' % commit_id)
 
         # try a direct git apply first
-        if not git.apply_diff(bottom, top):
-            git.merge_recursive(bottom, git.get_head(), top)
+        if not git.apply_diff(bottom, top, files = options.files):
+            if options.files:
+                raise CmdException, 'Patch folding failed'
+            else:
+                git.merge_recursive(bottom, git.get_head(), top)
 
         out.done()
     elif options.update:
@@ -152,6 +157,9 @@ def func(parser, options, args):
     if not args:
         parser.error('incorrect number of arguments')
 
+    if options.files and not options.fold:
+        parser.error('--file can only be specified with --fold')
+
     if not options.unapplied:
         check_local_changes()
         check_conflicts()

```

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

Subject: Re: [StGit PATCH] Add --file option to pick
Message-ID: <20090115082614.GA24890@diana.vm.bytemark.co.uk>
URL: https://gitlist.dev/e/20090115082614.GA24890%40diana.vm.bytemark.co.uk
In-Reply-To: <20090114225930.11098.2144.stgit@localhost.localdomain>

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

> +    opt('-f', '--files', action = 'append',
> +        short = 'Only fold the given files'),

The long form should probably be "--file", since you only list one
file for every flag (and since you call it "--file" in the last hunk).
And the help text could be something like

  Only fold the given file (for multiple files, use -f more than once)

> +                raise CmdException, 'Patch folding failed'

This is not important, but I believe the recommended syntax for
raising exceptions nowadays is

  CmdException('Patch folding failed')

since that's what'll continue to work in Python 3, or something like
that. (I see you already use it in the multi-line case in the other
patch, where this syntax is clearly the better choice.)

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

```
