##// 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 4066 ('', 'exact', None,
4067 4067 _('apply patch to the nodes from which it was generated')),
4068 4068 ('', 'prefix', '',
4069 _('apply patch to directory relative to the root'), _('DIR')),
4069 _('apply patch to subdirectory'), _('DIR')),
4070 4070 ('', 'import-branch', None,
4071 4071 _('use any branch information in patch (implied by --exact)'))] +
4072 4072 commitopts + commitopts2 + similarityopts,
@@ -17,6 +17,7 b' from i18n import _'
17 17 from node import hex, short
18 18 import cStringIO
19 19 import base85, mdiff, scmutil, util, diffhelpers, copies, encoding, error
20 import pathutil
20 21
21 22 gitre = re.compile('diff --git a/(.*) b/(.*)')
22 23 tabsplitter = re.compile(r'(\t+|[^\t]+)')
@@ -1795,8 +1796,10 b' def _applydiff(ui, fp, patcher, backend,'
1795 1796 eolmode='strict'):
1796 1797
1797 1798 if prefix:
1798 # clean up double slashes, lack of trailing slashes, etc
1799 prefix = util.normpath(prefix) + '/'
1799 prefix = pathutil.canonpath(backend.repo.root, backend.repo.getcwd(),
1800 prefix)
1801 if prefix != '':
1802 prefix += '/'
1800 1803 def pstrip(p):
1801 1804 return pathtransform(p, strip - 1, prefix)[1]
1802 1805
@@ -626,6 +626,33 b' Prefix with strip, renames, creates etc'
626 626 adding dir/d
627 627 adding dir/dir2/b
628 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 656 $ hg import --no-commit --prefix dir/ - <<EOF
630 657 > diff --git a/a b/a
631 658 > --- /dev/null
@@ -649,10 +676,10 b' Prefix with strip, renames, creates etc'
649 676 forgetting dir/a (glob)
650 677 reverting dir/d (glob)
651 678 $ rm dir/a
652 (test that prefixes are relative to the root)
679 (test that prefixes are relative to the cwd)
653 680 $ mkdir tmpdir
654 681 $ cd tmpdir
655 $ hg import --no-commit -p2 --prefix dir/ - <<EOF
682 $ hg import --no-commit -p2 --prefix ../dir/ - <<EOF
656 683 > diff --git a/foo/a b/foo/a
657 684 > new file mode 100644
658 685 > --- /dev/null
General Comments 0
You need to be logged in to leave comments. Login now