chiark / gitweb /
Add import -p option
authorCatalin Marinas <catalin.marinas@arm.com>
Tue, 8 Sep 2009 21:07:35 +0000 (22:07 +0100)
committerCatalin Marinas <catalin.marinas@arm.com>
Tue, 8 Sep 2009 21:45:13 +0000 (22:45 +0100)
This patch renames some of the existing import options and adds the -p
(--strip) option which allows stripping the leading slashes of the diff
paths.

Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
RELEASENOTES
stgit/commands/imprt.py
stgit/git.py
t/t1800-import.sh
t/t1800-import/git-diff-p0 [new file with mode: 0644]

index 0a220a462b8d23c81a15ebeaa156f69a6f5f1221..b333f8bfe54b594fea3948cd2cdb5c7b20fbda15 100644 (file)
@@ -37,6 +37,9 @@ The main changes since release 0.14.3 are
   - The commands "stg add", "stg rm", "stg cp", and "stg resolved"
     were removed, since there are corresponding Git equivalents
 
+  - The "stg import" command supports the "-p N" option for stripping
+    leading slashes from diff paths
+
   - New patch identification syntax: <branch>:<patch> (see
     documentation for the "stg id" command).
 
index 8067beb11adfaf0ebec52aa5c097eac08b2e8f25..0bbacbc5133c6e8f09147bb61c81949d070f4d51 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'),
@@ -69,7 +71,7 @@ options = [
         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'),
@@ -104,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:
@@ -152,9 +154,10 @@ def __create_patch(filename, message, author_name, author_email,
             base = git_id(crt_series, options.base)
         else:
             base = None
-        git.apply_patch(diff = diff, base = base, reject = options.reject)
+        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()
index 268c44b37be012acf76108fff7f909f981068da3..012e2826d6b62c45bc6dae288ba0c7679dbb7070 100644 (file)
@@ -818,7 +818,7 @@ def repack():
     GRun('repack', '-a', '-d', '-f').run()
 
 def apply_patch(filename = None, diff = None, base = None,
-                fail_dump = True, reject = False):
+                fail_dump = True, reject = False, strip = None):
     """Apply a patch onto the current or given index. There must not
     be any local changes in the tree, otherwise the command fails
     """
@@ -840,6 +840,8 @@ def apply_patch(filename = None, diff = None, base = None,
     cmd = ['apply', '--index']
     if reject:
         cmd += ['--reject']
+    if strip != None:
+        cmd += ['-p', str(strip)]
     try:
         GRun(*cmd).raw_input(diff).no_output()
     except GitRunException:
index ecaa5934c28eb556a3f5b255870392fe3720f5a4..93de794ec5b7a9497cba83c1bc342353ef19afb9 100755 (executable)
@@ -21,6 +21,33 @@ test_expect_success \
     stg delete ..
     '
 
+test_expect_success \
+    'Apply a patch created with "git diff" using -p1' \
+    '
+    stg import -p1 ../t1800-import/git-diff &&
+    [ $(git cat-file -p $(stg id) \
+        | grep -c "tree e96b1fba2160890ff600b675d7140d46b022b155") = 1 ] &&
+    stg delete ..
+    '
+
+test_expect_success \
+    'Apply a patch created with "git diff" using -p0' \
+    '
+    stg import -p0 ../t1800-import/git-diff-p0 &&
+    [ $(git cat-file -p $(stg id) \
+        | grep -c "tree e96b1fba2160890ff600b675d7140d46b022b155") = 1 ] &&
+    stg delete ..
+    '
+
+test_expect_success \
+    'Apply a patch created with "git diff" using -p2' \
+    '
+    ! stg import -p2 ../t1800-import/git-diff &&
+    [ $(git cat-file -p $(stg id) \
+        | grep -c "tree a5850c97490398571d41d6304dd940800550f507") = 1 ] &&
+    stg delete ..
+    '
+
 test_expect_success \
     'Apply a patch created with "git diff" from a subdirectory' \
     '
diff --git a/t/t1800-import/git-diff-p0 b/t/t1800-import/git-diff-p0
new file mode 100644 (file)
index 0000000..f13158e
--- /dev/null
@@ -0,0 +1,20 @@
+diff --git foo.txt foo.txt
+index ad01662..d3cd5b6 100644
+--- foo.txt
++++ foo.txt
+@@ -3,6 +3,7 @@ dobedim
+ dobedum
+ dobidam
+ dobidim
++dabadadash
+ dobidum
+ dobodam
+ dobodim
+@@ -20,6 +21,7 @@ dabedam
+ dabedim
+ dabedum
+ dabidam
++dadadadash
+ dabidim
+ dabidum
+ dabodam