##// END OF EJS Templates
patch._applydiff: resolve prefix with respect to the cwd...
Siddharth Agarwal -
r24390:72d7d390 default
parent child Browse files
Show More
@@ -4066,7 +4066,7 b' def identify(ui, repo, source=None, rev='
4066 ('', 'exact', None,
4066 ('', 'exact', None,
4067 _('apply patch to the nodes from which it was generated')),
4067 _('apply patch to the nodes from which it was generated')),
4068 ('', 'prefix', '',
4068 ('', 'prefix', '',
4069 _('apply patch to directory relative to the root'), _('DIR')),
4069 _('apply patch to subdirectory'), _('DIR')),
4070 ('', 'import-branch', None,
4070 ('', 'import-branch', None,
4071 _('use any branch information in patch (implied by --exact)'))] +
4071 _('use any branch information in patch (implied by --exact)'))] +
4072 commitopts + commitopts2 + similarityopts,
4072 commitopts + commitopts2 + similarityopts,
@@ -17,6 +17,7 b' from i18n import _'
17 from node import hex, short
17 from node import hex, short
18 import cStringIO
18 import cStringIO
19 import base85, mdiff, scmutil, util, diffhelpers, copies, encoding, error
19 import base85, mdiff, scmutil, util, diffhelpers, copies, encoding, error
20 import pathutil
20
21
21 gitre = re.compile('diff --git a/(.*) b/(.*)')
22 gitre = re.compile('diff --git a/(.*) b/(.*)')
22 tabsplitter = re.compile(r'(\t+|[^\t]+)')
23 tabsplitter = re.compile(r'(\t+|[^\t]+)')
@@ -1795,8 +1796,10 b' def _applydiff(ui, fp, patcher, backend,'
1795 eolmode='strict'):
1796 eolmode='strict'):
1796
1797
1797 if prefix:
1798 if prefix:
1798 # clean up double slashes, lack of trailing slashes, etc
1799 prefix = pathutil.canonpath(backend.repo.root, backend.repo.getcwd(),
1799 prefix = util.normpath(prefix) + '/'
1800 prefix)
1801 if prefix != '':
1802 prefix += '/'
1800 def pstrip(p):
1803 def pstrip(p):
1801 return pathtransform(p, strip - 1, prefix)[1]
1804 return pathtransform(p, strip - 1, prefix)[1]
1802
1805
@@ -626,6 +626,33 b' Prefix with strip, renames, creates etc'
626 adding dir/d
626 adding dir/d
627 adding dir/dir2/b
627 adding dir/dir2/b
628 adding dir/dir2/c
628 adding dir/dir2/c
629
630 prefix '.' is the same as no prefix
631 $ hg import --no-commit --prefix . - <<EOF
632 > diff --git a/dir/a b/dir/a
633 > --- /dev/null
634 > +++ b/dir/a
635 > @@ -0,0 +1 @@
636 > +aaaa
637 > diff --git a/dir/d b/dir/d
638 > --- a/dir/d
639 > +++ b/dir/d
640 > @@ -1,1 +1,2 @@
641 > d
642 > +dddd
643 > EOF
644 applying patch from stdin
645 $ cat dir/a
646 aaaa
647 $ cat dir/d
648 d
649 dddd
650 $ hg revert -aC
651 forgetting dir/a (glob)
652 reverting dir/d (glob)
653 $ rm dir/a
654
655 prefix with default strip
629 $ hg import --no-commit --prefix dir/ - <<EOF
656 $ hg import --no-commit --prefix dir/ - <<EOF
630 > diff --git a/a b/a
657 > diff --git a/a b/a
631 > --- /dev/null
658 > --- /dev/null
@@ -649,10 +676,10 b' Prefix with strip, renames, creates etc'
649 forgetting dir/a (glob)
676 forgetting dir/a (glob)
650 reverting dir/d (glob)
677 reverting dir/d (glob)
651 $ rm dir/a
678 $ rm dir/a
652 (test that prefixes are relative to the root)
679 (test that prefixes are relative to the cwd)
653 $ mkdir tmpdir
680 $ mkdir tmpdir
654 $ cd tmpdir
681 $ cd tmpdir
655 $ hg import --no-commit -p2 --prefix dir/ - <<EOF
682 $ hg import --no-commit -p2 --prefix ../dir/ - <<EOF
656 > diff --git a/foo/a b/foo/a
683 > diff --git a/foo/a b/foo/a
657 > new file mode 100644
684 > new file mode 100644
658 > --- /dev/null
685 > --- /dev/null
General Comments 0
You need to be logged in to leave comments. Login now