[PATCH 3 of 3 relative-import] cmdutil.tryimportone: allow importing relative patches with --bypass

Siddharth Agarwal sid0 at fb.com
Tue Mar 10 15:49:57 CDT 2015


# HG changeset patch
# User Siddharth Agarwal <sid0 at fb.com>
# Date 1426017998 25200
#      Tue Mar 10 13:06:38 2015 -0700
# Node ID 3e53b265bbd50bfb53dca40898314e42550700b9
# Parent  a7cb4e2a12a100353ffe96ca2ea256b503ebfea4
cmdutil.tryimportone: allow importing relative patches with --bypass

diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -713,7 +713,7 @@
             try:
                 files = set()
                 try:
-                    patch.patchrepo(ui, repo, p1, store, tmpname, strip,
+                    patch.patchrepo(ui, repo, p1, store, tmpname, strip, prefix,
                                     files, eolmode=None)
                 except patch.PatchError, e:
                     raise util.Abort(str(e))
diff --git a/mercurial/patch.py b/mercurial/patch.py
--- a/mercurial/patch.py
+++ b/mercurial/patch.py
@@ -1528,10 +1528,10 @@
     backend = workingbackend(ui, repo, similarity)
     return patchbackend(ui, backend, patchobj, strip, prefix, files, eolmode)
 
-def patchrepo(ui, repo, ctx, store, patchobj, strip, files=None,
+def patchrepo(ui, repo, ctx, store, patchobj, strip, prefix, files=None,
               eolmode='strict'):
     backend = repobackend(ui, repo, ctx, store)
-    return patchbackend(ui, backend, patchobj, strip, '', files, eolmode)
+    return patchbackend(ui, backend, patchobj, strip, prefix, files, eolmode)
 
 def patch(ui, repo, patchname, strip=1, prefix='', files=None, eolmode='strict',
           similarity=0):
diff --git a/tests/test-import-bypass.t b/tests/test-import-bypass.t
--- a/tests/test-import-bypass.t
+++ b/tests/test-import-bypass.t
@@ -104,6 +104,86 @@
   $ hg rollback
   repository tip rolled back to revision 1 (undo import)
 
+Test --strip with --bypass
+
+  $ mkdir -p dir/dir2
+  $ echo bb > dir/dir2/b
+  $ echo cc > dir/dir2/c
+  $ echo d > dir/d
+  $ hg ci -Am 'addabcd'
+  adding dir/d
+  adding dir/dir2/b
+  adding dir/dir2/c
+  $ shortlog
+  @  2:d805bc8236b6 test 0 0 - default - addabcd
+  |
+  | o  1:4e322f7ce8e3 test 0 0 - foo - changea
+  |/
+  o  0:07f494440405 test 0 0 - default - adda
+  
+  $ hg import --bypass --strip 2 --prefix dir/ - <<EOF
+  > # HG changeset patch
+  > # User test
+  > # Date 0 0
+  > # Branch foo
+  > changeabcd
+  > 
+  > diff --git a/foo/a b/foo/a
+  > new file mode 100644
+  > --- /dev/null
+  > +++ b/foo/a
+  > @@ -0,0 +1 @@
+  > +a
+  > diff --git a/foo/dir2/b b/foo/dir2/b2
+  > rename from foo/dir2/b
+  > rename to foo/dir2/b2
+  > diff --git a/foo/dir2/c b/foo/dir2/c
+  > --- a/foo/dir2/c
+  > +++ b/foo/dir2/c
+  > @@ -0,0 +1 @@
+  > +cc
+  > diff --git a/foo/d b/foo/d
+  > deleted file mode 100644
+  > --- a/foo/d
+  > +++ /dev/null
+  > @@ -1,1 +0,0 @@
+  > -d
+  > EOF
+  applying patch from stdin
+
+  $ shortlog
+  o  3:5bd46886ca3e test 0 0 - default - changeabcd
+  |
+  @  2:d805bc8236b6 test 0 0 - default - addabcd
+  |
+  | o  1:4e322f7ce8e3 test 0 0 - foo - changea
+  |/
+  o  0:07f494440405 test 0 0 - default - adda
+  
+  $ hg diff --change 3 --git
+  diff --git a/dir/a b/dir/a
+  new file mode 100644
+  --- /dev/null
+  +++ b/dir/a
+  @@ -0,0 +1,1 @@
+  +a
+  diff --git a/dir/d b/dir/d
+  deleted file mode 100644
+  --- a/dir/d
+  +++ /dev/null
+  @@ -1,1 +0,0 @@
+  -d
+  diff --git a/dir/dir2/b b/dir/dir2/b2
+  rename from dir/dir2/b
+  rename to dir/dir2/b2
+  diff --git a/dir/dir2/c b/dir/dir2/c
+  --- a/dir/dir2/c
+  +++ b/dir/dir2/c
+  @@ -1,1 +1,2 @@
+   cc
+  +cc
+  $ hg -q --config extensions.strip= strip .
+
 Test unsupported combinations
 
   $ hg import --bypass --no-commit ../test.diff


More information about the Mercurial-devel mailing list