+
+def func(parser, options, args):
+ """Import a commit object as a new patch
+ """
+ if not args:
+ parser.error('incorrect number of arguments')
+
+ if not options.unapplied:
+ check_local_changes()
+ check_conflicts()
+ check_head_top_equal(crt_series)
+
+ if options.ref_branch:
+ remote_series = Series(options.ref_branch)
+ else:
+ remote_series = crt_series
+
+ applied = remote_series.get_applied()
+ unapplied = remote_series.get_unapplied()
+ try:
+ patches = parse_patches(args, applied + unapplied, len(applied))
+ commit_id = None
+ except CmdException:
+ if len(args) > 1:
+ raise
+ # no patches found, try a commit id
+ commit_id = git_id(remote_series, args[0])
+
+ if not commit_id and len(patches) > 1:
+ if options.name:
+ raise CmdException, '--name can only be specified with one patch'
+ 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():
+ raise CmdException, 'No patches applied'
+
+ if commit_id:
+ __pick_commit(commit_id, None, options)
+ else:
+ if options.unapplied:
+ patches.reverse()
+ for patch in patches:
+ __pick_commit(git_id(remote_series, patch), patch, options)
+