Add import -p option
[stgit] / stgit / commands / imprt.py
index 97a6a09..0bbacbc 100644 (file)
@@ -57,7 +57,9 @@ options = [
         short = 'Import a patch from a URL'),
     opt('-n', '--name',
         short = 'Use NAME as the patch name'),
-    opt('-t', '--strip', action = 'store_true',
+    opt('-p', '--strip', type = 'int', metavar = 'N',
+        short = 'Remove N leading slashes from diff paths (default 1)'),
+    opt('-t', '--stripname', action = 'store_true',
         short = 'Strip numbering and extension from patch name'),
     opt('-i', '--ignore', action = 'store_true',
         short = 'Ignore the applied patches in the series'),
@@ -65,9 +67,11 @@ options = [
         short = 'Replace the unapplied patches in the series'),
     opt('-b', '--base', args = [argparse.commit],
         short = 'Use BASE instead of HEAD for file importing'),
+    opt('--reject', action = 'store_true',
+        short = 'leave the rejected hunks in corresponding *.rej files'),
     opt('-e', '--edit', action = 'store_true',
         short = 'Invoke an editor for the patch description'),
-    opt('-p', '--showpatch', action = 'store_true',
+    opt('-d', '--showdiff', action = 'store_true',
         short = 'Show the patch content in the editor buffer'),
     opt('-a', '--author', metavar = '"NAME <EMAIL>"',
         short = 'Use "NAME <EMAIL>" as the author details'),
@@ -102,7 +106,7 @@ def __create_patch(filename, message, author_name, author_email,
         patch = os.path.basename(filename)
     else:
         patch = ''
-    if options.strip:
+    if options.stripname:
         patch = __strip_patch_name(patch)
 
     if not patch:
@@ -147,12 +151,13 @@ def __create_patch(filename, message, author_name, author_email,
     else:
         out.start('Importing patch "%s"' % patch)
         if options.base:
-            git.apply_patch(diff = diff,
-                            base = git_id(crt_series, options.base))
+            base = git_id(crt_series, options.base)
         else:
-            git.apply_patch(diff = diff)
+            base = None
+        git.apply_patch(diff = diff, base = base, reject = options.reject,
+                        strip = options.strip)
         crt_series.refresh_patch(edit = options.edit,
-                                 show_patch = options.showpatch,
+                                 show_patch = options.showdiff,
                                  sign_str = options.sign_str,
                                  backup = False)
         out.done()
@@ -265,7 +270,7 @@ def __import_url(url, options):
     import tempfile
 
     if not url:
-        parser.error('URL argument required')
+        raise CmdException('URL argument required')
 
     patch = os.path.basename(urllib.unquote(url))
     filename = os.path.join(tempfile.gettempdir(), patch)
@@ -325,7 +330,7 @@ def func(parser, options, args):
     else:
         filename = None
 
-    if filename:
+    if not options.url and filename:
         filename = os.path.abspath(filename)
     directory.cd_to_topdir()