Mercurial > hg
changeset 24259:5ac8ce04baa2
cmdutil.tryimportone: allow importing relative patches into the working dir
This makes hg import --prefix dir/ (without bypass) work.
author | Siddharth Agarwal <sid0@fb.com> |
---|---|
date | Mon, 09 Mar 2015 18:22:24 -0700 |
parents | 093e8a5e995f |
children | 76225ab5a5da |
files | mercurial/cmdutil.py mercurial/patch.py tests/test-import-git.t tests/test-import.t |
diffstat | 4 files changed, 77 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/cmdutil.py Fri Mar 06 22:56:19 2015 -0800 +++ b/mercurial/cmdutil.py Mon Mar 09 18:22:24 2015 -0700 @@ -615,6 +615,7 @@ update = not opts.get('bypass') strip = opts["strip"] + prefix = opts["prefix"] sim = float(opts.get('similarity') or 0) if not tmpname: return (None, None, False) @@ -674,8 +675,8 @@ partial = opts.get('partial', False) files = set() try: - patch.patch(ui, repo, tmpname, strip=strip, files=files, - eolmode=None, similarity=sim / 100.0) + patch.patch(ui, repo, tmpname, strip=strip, prefix=prefix, + files=files, eolmode=None, similarity=sim / 100.0) except patch.PatchError, e: if not partial: raise util.Abort(str(e))
--- a/mercurial/patch.py Fri Mar 06 22:56:19 2015 -0800 +++ b/mercurial/patch.py Mon Mar 09 18:22:24 2015 -0700 @@ -1533,7 +1533,7 @@ backend = repobackend(ui, repo, ctx, store) return patchbackend(ui, backend, patchobj, strip, '', files, eolmode) -def patch(ui, repo, patchname, strip=1, files=None, eolmode='strict', +def patch(ui, repo, patchname, strip=1, prefix='', files=None, eolmode='strict', similarity=0): """Apply <patchname> to the working directory. @@ -1552,7 +1552,7 @@ if patcher: return _externalpatch(ui, repo, patcher, patchname, strip, files, similarity) - return internalpatch(ui, repo, patchname, strip, '', files, eolmode, + return internalpatch(ui, repo, patchname, strip, prefix, files, eolmode, similarity) def changedfiles(ui, repo, patchpath, strip=1):
--- a/tests/test-import-git.t Fri Mar 06 22:56:19 2015 -0800 +++ b/tests/test-import-git.t Mon Mar 09 18:22:24 2015 -0700 @@ -612,12 +612,64 @@ a R a -Renames, similarity and git diff +Prefix with strip, renames, creates etc $ hg revert -aC undeleting a forgetting b $ rm b + $ mkdir -p dir/dir2 + $ echo b > dir/dir2/b + $ echo c > dir/dir2/c + $ echo d > dir/d + $ hg ci -Am addbcd + adding dir/d + adding dir/dir2/b + adding dir/dir2/c +(test that prefixes are relative to the root) + $ mkdir tmpdir + $ cd tmpdir + $ hg import --no-commit -p2 --prefix dir/ - <<EOF + > 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 + $ hg st --copies + M dir/dir2/c + A dir/a + A dir/dir2/b2 + dir/dir2/b + R dir/d + R dir/dir2/b + $ cd .. + +Renames, similarity and git diff + + $ hg revert -aC + forgetting dir/a (glob) + undeleting dir/d (glob) + undeleting dir/dir2/b (glob) + forgetting dir/dir2/b2 (glob) + reverting dir/dir2/c (glob) + $ rm dir/a dir/dir2/b2 $ hg import --similarity 90 --no-commit - <<EOF > diff --git a/a b/b > rename from a
--- a/tests/test-import.t Fri Mar 06 22:56:19 2015 -0800 +++ b/tests/test-import.t Mon Mar 09 18:22:24 2015 -0700 @@ -670,6 +670,25 @@ $ hg status $ cat a bb + +test --prefix + + $ mkdir -p dir/dir2 + $ echo b > dir/dir2/b + $ hg ci -Am b + adding dir/dir2/b + $ hg import -p2 --prefix dir - << EOF + > foobar + > --- drop1/drop2/dir2/b + > +++ drop1/drop2/dir2/b + > @@ -1,1 +1,1 @@ + > -b + > +cc + > EOF + applying patch from stdin + $ hg status + $ cat dir/dir2/b + cc $ cd ..