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', '--file', action = 'append',
+ short = 'Only fold the given file (can be used multiple times)'),
opt('--unapplied', action = 'store_true',
short = 'Keep the patch unapplied')]
if options.name:
patchname = options.name
+ if patchname:
+ patchname = find_patch_name(patchname, crt_series.patch_exists)
if options.parent:
parent = git_id(crt_series, options.parent)
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.file):
+ if options.file:
+ raise CmdException('Patch folding failed')
+ else:
+ git.merge_recursive(bottom, git.get_head(), top)
out.done()
elif options.update:
if not args:
parser.error('incorrect number of arguments')
+ if options.file and not options.fold:
+ parser.error('--file can only be specified with --fold')
+
if not options.unapplied:
check_local_changes()
check_conflicts()
if options.parent:
raise CmdException, '--parent can only be specified with one patch'
- if (options.fold or options.update) and not crt_series.get_current():
+ if options.update and not crt_series.get_current():
raise CmdException, 'No patches applied'
if commit_id:
- __pick_commit(commit_id, None, options)
+ # Try to guess a patch name if the argument was <branch>:<patch>
+ try:
+ patchname = args[0].split(':')[1]
+ except IndexError:
+ patchname = None
+ __pick_commit(commit_id, patchname, options)
else:
if options.unapplied:
patches.reverse()