Skip to content
Snippets Groups Projects
test-import.t 39.2 KiB
Newer Older
Nicolas Dumazet's avatar
Nicolas Dumazet committed
  $ hg init a
  $ mkdir a/d1
  $ mkdir a/d1/d2
  $ echo line 1 > a/a
  $ echo line 1 > a/d1/d2/a
  $ hg --cwd a ci -Ama
  adding a
  adding d1/d2/a

  $ echo line 2 >> a/a
  $ hg --cwd a ci -u someone -d '1 0' -m'second change'

import with no args:

  $ hg --cwd a import
  abort: need at least one patch to import
  [255]
generate patches for the test

  $ hg --cwd a export tip > exported-tip.patch
  $ hg --cwd a diff -r0:1 > diffed-tip.patch


Nicolas Dumazet's avatar
Nicolas Dumazet committed
import exported patch
(this also tests that editor is not invoked, if the patch contains the
commit message and '--edit' is not specified)
Nicolas Dumazet's avatar
Nicolas Dumazet committed

  $ hg clone -r0 a b
  adding changesets
  adding manifests
  adding file changes
  added 1 changesets with 2 changes to 2 files
  updating to branch default
  2 files updated, 0 files merged, 0 files removed, 0 files unresolved
  $ HGEDITOR=cat hg --cwd b import ../exported-tip.patch
message and committer and date should be same
  $ hg --cwd b tip
  changeset:   1:1d4bd90af0e4
  tag:         tip
  user:        someone
  date:        Thu Jan 01 00:00:01 1970 +0000
Nicolas Dumazet's avatar
Nicolas Dumazet committed
  summary:     second change
Nicolas Dumazet's avatar
Nicolas Dumazet committed
  $ rm -r b


import exported patch with external patcher
(this also tests that editor is invoked, if the '--edit' is specified,
regardless of the commit message in the patch)
Nicolas Dumazet's avatar
Nicolas Dumazet committed

  $ cat > dummypatch.py <<EOF
  > from __future__ import print_function
  > print('patching file a')
Nicolas Dumazet's avatar
Nicolas Dumazet committed
  > file('a', 'wb').write('line2\n')
  > EOF
  $ hg clone -r0 a b
  adding changesets
  adding manifests
  adding file changes
  added 1 changesets with 2 changes to 2 files
  updating to branch default
  2 files updated, 0 files merged, 0 files removed, 0 files unresolved
  $ HGEDITOR=cat hg --config ui.patch="$PYTHON ../dummypatch.py" --cwd b import --edit ../exported-tip.patch
  second change
  
  
  HG: Enter commit message.  Lines beginning with 'HG:' are removed.
  HG: Leave message empty to abort commit.
  HG: --
  HG: user: someone
  HG: branch 'default'
  HG: changed a
Nicolas Dumazet's avatar
Nicolas Dumazet committed
  $ cat b/a
  line2
  $ rm -r b


import of plain diff should fail without message
(this also tests that editor is invoked, if the patch doesn't contain
the commit message, regardless of '--edit')
Nicolas Dumazet's avatar
Nicolas Dumazet committed

  $ hg clone -r0 a b
  adding changesets
  adding manifests
  adding file changes
  added 1 changesets with 2 changes to 2 files
  updating to branch default
  2 files updated, 0 files merged, 0 files removed, 0 files unresolved
  $ cat > $TESTTMP/editor.sh <<EOF
  > env | grep HGEDITFORM
  > cat \$1
  > EOF
  $ HGEDITOR="sh $TESTTMP/editor.sh" hg --cwd b import ../diffed-tip.patch
  
  
  HG: Enter commit message.  Lines beginning with 'HG:' are removed.
  HG: Leave message empty to abort commit.
  HG: --
  HG: user: test
  HG: branch 'default'
  HG: changed a
Nicolas Dumazet's avatar
Nicolas Dumazet committed
  abort: empty commit message

Test avoiding editor invocation at applying the patch with --exact,
even if commit message is empty

  $ echo a >> b/a
  $ hg --cwd b commit -m ' '
  $ hg --cwd b tip -T "{node}\n"
  d8804f3f5396d800812f579c8452796a5993bdb2
  $ hg --cwd b export -o ../empty-log.diff .
  $ hg --cwd b update -q -C ".^1"
  $ hg --cwd b --config extensions.strip= strip -q tip
  $ HGEDITOR=cat hg --cwd b import --exact ../empty-log.diff
  applying ../empty-log.diff
  $ hg --cwd b tip -T "{node}\n"
  d8804f3f5396d800812f579c8452796a5993bdb2

Nicolas Dumazet's avatar
Nicolas Dumazet committed
  $ rm -r b


import of plain diff should be ok with message

  $ hg clone -r0 a b
  adding changesets
  adding manifests
  adding file changes
  added 1 changesets with 2 changes to 2 files
  updating to branch default
  2 files updated, 0 files merged, 0 files removed, 0 files unresolved
  $ hg --cwd b import -mpatch ../diffed-tip.patch
  applying ../diffed-tip.patch
Nicolas Dumazet's avatar
Nicolas Dumazet committed
  $ rm -r b


import of plain diff with specific date and user
(this also tests that editor is not invoked, if
'--message'/'--logfile' is specified and '--edit' is not)
Nicolas Dumazet's avatar
Nicolas Dumazet committed

  $ hg clone -r0 a b
  adding changesets
  adding manifests
  adding file changes
  added 1 changesets with 2 changes to 2 files
  updating to branch default
  2 files updated, 0 files merged, 0 files removed, 0 files unresolved
  $ hg --cwd b import -mpatch -d '1 0' -u 'user@nowhere.net' ../diffed-tip.patch
  applying ../diffed-tip.patch
Nicolas Dumazet's avatar
Nicolas Dumazet committed
  $ hg -R b tip -pv
  changeset:   1:ca68f19f3a40
  tag:         tip
  user:        user@nowhere.net
  date:        Thu Jan 01 00:00:01 1970 +0000
  files:       a
  description:
  patch
  
  
  diff -r 80971e65b431 -r ca68f19f3a40 a
  --- a/a	Thu Jan 01 00:00:00 1970 +0000
  +++ b/a	Thu Jan 01 00:00:01 1970 +0000
  @@ -1,1 +1,2 @@
   line 1
  +line 2
  
  $ rm -r b


import of plain diff should be ok with --no-commit
(this also tests that editor is not invoked, if '--no-commit' is
specified, regardless of '--edit')
Nicolas Dumazet's avatar
Nicolas Dumazet committed

  $ hg clone -r0 a b
  adding changesets
  adding manifests
  adding file changes
  added 1 changesets with 2 changes to 2 files
  updating to branch default
  2 files updated, 0 files merged, 0 files removed, 0 files unresolved
  $ HGEDITOR=cat hg --cwd b import --no-commit --edit ../diffed-tip.patch
Nicolas Dumazet's avatar
Nicolas Dumazet committed
  $ hg --cwd b diff --nodates
  diff -r 80971e65b431 a
  --- a/a
  +++ b/a
  @@ -1,1 +1,2 @@
   line 1
  +line 2
  $ rm -r b


import of malformed plain diff should fail

  $ hg clone -r0 a b
  adding changesets
  adding manifests
  adding file changes
  added 1 changesets with 2 changes to 2 files
  updating to branch default
  2 files updated, 0 files merged, 0 files removed, 0 files unresolved
  $ sed 's/1,1/foo/' < diffed-tip.patch > broken.patch
  $ hg --cwd b import -mpatch ../broken.patch
  applying ../broken.patch
  abort: bad hunk #1
  [255]
  $ rm -r b


Nicolas Dumazet's avatar
Nicolas Dumazet committed
hg -R repo import
put the clone in a subdir - having a directory named "a"
used to hide a bug.

  $ mkdir dir
  $ hg clone -r0 a dir/b
  adding changesets
  adding manifests
  adding file changes
  added 1 changesets with 2 changes to 2 files
  updating to branch default
  2 files updated, 0 files merged, 0 files removed, 0 files unresolved
  $ cd dir
  $ hg -R b import ../exported-tip.patch
  applying ../exported-tip.patch
Nicolas Dumazet's avatar
Nicolas Dumazet committed
  $ cd ..
  $ rm -r dir


import from stdin

  $ hg clone -r0 a b
  adding changesets
  adding manifests
  adding file changes
  added 1 changesets with 2 changes to 2 files
  updating to branch default
  2 files updated, 0 files merged, 0 files removed, 0 files unresolved
  $ hg --cwd b import - < exported-tip.patch
Nicolas Dumazet's avatar
Nicolas Dumazet committed
  applying patch from stdin
  $ rm -r b


import two patches in one stream

  $ hg init b
  $ hg --cwd a export 0:tip | hg --cwd b import -
  applying patch from stdin
  $ hg --cwd a id
  1d4bd90af0e4 tip
  $ hg --cwd b id
  1d4bd90af0e4 tip
  $ rm -r b


override commit message

  $ hg clone -r0 a b
  adding changesets
  adding manifests
  adding file changes
  added 1 changesets with 2 changes to 2 files
  updating to branch default
  2 files updated, 0 files merged, 0 files removed, 0 files unresolved
  $ hg --cwd b import -m 'override' - < exported-tip.patch
Nicolas Dumazet's avatar
Nicolas Dumazet committed
  applying patch from stdin
  $ hg --cwd b tip | grep override
  summary:     override
  $ rm -r b

  $ cat > mkmsg.py <<EOF
  > import email.Message, sys
  > msg = email.Message.Message()
  > patch = open(sys.argv[1], 'rb').read()
  > msg.set_payload('email commit message\n' + patch)
Nicolas Dumazet's avatar
Nicolas Dumazet committed
  > msg['Subject'] = 'email patch'
  > msg['From'] = 'email patcher'
  > file(sys.argv[2], 'wb').write(msg.as_string())
Nicolas Dumazet's avatar
Nicolas Dumazet committed
  > EOF


plain diff in email, subject, message body

  $ hg clone -r0 a b
  adding changesets
  adding manifests
  adding file changes
  added 1 changesets with 2 changes to 2 files
  updating to branch default
  2 files updated, 0 files merged, 0 files removed, 0 files unresolved
  $ $PYTHON mkmsg.py diffed-tip.patch msg.patch
Nicolas Dumazet's avatar
Nicolas Dumazet committed
  $ hg --cwd b import ../msg.patch
  applying ../msg.patch
  $ hg --cwd b tip | grep email
  user:        email patcher
  summary:     email patch
  $ rm -r b


plain diff in email, no subject, message body

  $ hg clone -r0 a b
  adding changesets
  adding manifests
  adding file changes
  added 1 changesets with 2 changes to 2 files
  updating to branch default
  2 files updated, 0 files merged, 0 files removed, 0 files unresolved
  $ grep -v '^Subject:' msg.patch | hg --cwd b import -
  applying patch from stdin
  $ rm -r b


plain diff in email, subject, no message body

  $ hg clone -r0 a b
  adding changesets
  adding manifests
  adding file changes
  added 1 changesets with 2 changes to 2 files
  updating to branch default
  2 files updated, 0 files merged, 0 files removed, 0 files unresolved
  $ grep -v '^email ' msg.patch | hg --cwd b import -
  applying patch from stdin
  $ rm -r b


plain diff in email, no subject, no message body, should fail

  $ hg clone -r0 a b
  adding changesets
  adding manifests
  adding file changes
  added 1 changesets with 2 changes to 2 files
  updating to branch default
  2 files updated, 0 files merged, 0 files removed, 0 files unresolved
  $ egrep -v '^(Subject|email)' msg.patch | hg --cwd b import -
  applying patch from stdin
  abort: empty commit message
Nicolas Dumazet's avatar
Nicolas Dumazet committed
  $ rm -r b


hg export in email, should use patch header

  $ hg clone -r0 a b
  adding changesets
  adding manifests
  adding file changes
  added 1 changesets with 2 changes to 2 files
  updating to branch default
  2 files updated, 0 files merged, 0 files removed, 0 files unresolved
  $ $PYTHON mkmsg.py exported-tip.patch msg.patch
  $ cat msg.patch | hg --cwd b import -
Nicolas Dumazet's avatar
Nicolas Dumazet committed
  applying patch from stdin
  $ hg --cwd b tip | grep second
  summary:     second change
  $ rm -r b


subject: duplicate detection, removal of [PATCH]
The '---' tests the gitsendmail handling without proper mail headers

  $ cat > mkmsg2.py <<EOF
  > import email.Message, sys
  > msg = email.Message.Message()
  > patch = open(sys.argv[1], 'rb').read()
  > msg.set_payload('email patch\n\nnext line\n---\n' + patch)
Nicolas Dumazet's avatar
Nicolas Dumazet committed
  > msg['Subject'] = '[PATCH] email patch'
  > msg['From'] = 'email patcher'
  > file(sys.argv[2], 'wb').write(msg.as_string())
Nicolas Dumazet's avatar
Nicolas Dumazet committed
  > EOF


plain diff in email, [PATCH] subject, message body with subject

  $ hg clone -r0 a b
  adding changesets
  adding manifests
  adding file changes
  added 1 changesets with 2 changes to 2 files
  updating to branch default
  2 files updated, 0 files merged, 0 files removed, 0 files unresolved
  $ $PYTHON mkmsg2.py diffed-tip.patch msg.patch
  $ cat msg.patch | hg --cwd b import -
Nicolas Dumazet's avatar
Nicolas Dumazet committed
  applying patch from stdin
  $ hg --cwd b tip --template '{desc}\n'
  email patch
  
  next line
  $ rm -r b


Issue963: Parent of working dir incorrect after import of multiple
patches and rollback

We weren't backing up the correct dirstate file when importing many
patches: import patch1 patch2; rollback
Nicolas Dumazet's avatar
Nicolas Dumazet committed

  $ echo line 3 >> a/a
  $ hg --cwd a ci -m'third change'
  $ hg --cwd a export -o '../patch%R' 1 2
  $ hg clone -qr0 a b
  $ hg --cwd b parents --template 'parent: {rev}\n'
  parent: 0
  $ hg --cwd b import -v ../patch1 ../patch2
Nicolas Dumazet's avatar
Nicolas Dumazet committed
  applying ../patch1
  committing manifest
  committing changelog
Nicolas Dumazet's avatar
Nicolas Dumazet committed
  applying ../patch2
  committing manifest
  committing changelog
Nicolas Dumazet's avatar
Nicolas Dumazet committed
  $ hg --cwd b rollback
  repository tip rolled back to revision 0 (undo import)
  working directory now based on revision 0
Nicolas Dumazet's avatar
Nicolas Dumazet committed
  $ hg --cwd b parents --template 'parent: {rev}\n'

Test that "hg rollback" doesn't restore dirstate to one at the
beginning of the rolled back transaction in not-"parent-gone" case.

invoking pretxncommit hook will cause marking '.hg/dirstate' as a file
to be restored when rolling back, after DirstateTransactionPlan (see wiki
page for detail).

  $ hg --cwd b branch -q foobar
  $ hg --cwd b commit -m foobar
  $ hg --cwd b update 0 -q
  $ hg --cwd b import ../patch1 ../patch2 --config hooks.pretxncommit=true
  applying ../patch1
  applying ../patch2
  $ hg --cwd b update -q 1
  $ hg --cwd b rollback -q
  $ hg --cwd b parents --template 'parent: {rev}\n'
  parent: 1

  $ hg --cwd b update -q -C 0
  $ hg --cwd b --config extensions.strip= strip -q 1

Test visibility of in-memory dirstate changes inside transaction to
external process

  $ echo foo > a/foo
  $ hg --cwd a commit -A -m 'adding foo' foo
  $ hg --cwd a export -o '../patch%R' 3

  $ cat > $TESTTMP/checkvisibility.sh <<EOF
  > echo "===="
  > hg parents --template "VISIBLE {rev}:{node|short}\n"
  > hg status -amr
  > # test that pending changes are hidden
  > unset HG_PENDING
  > hg parents --template "ACTUAL  {rev}:{node|short}\n"
  > hg status -amr
  > echo "===="
  > EOF

== test visibility to external editor

  $ (cd b && sh "$TESTTMP/checkvisibility.sh")
  ====
  VISIBLE 0:80971e65b431
  ACTUAL  0:80971e65b431
  ====

  $ HGEDITOR="sh $TESTTMP/checkvisibility.sh" hg --cwd b import -v --edit ../patch1 ../patch2 ../patch3
  applying ../patch1
  patching file a
  ====
  VISIBLE 0:80971e65b431
  M a
  ACTUAL  0:80971e65b431
  M a
  ====
  committing files:
  a
  committing manifest
  committing changelog
  created 1d4bd90af0e4
  applying ../patch2
  patching file a
  ====
  VISIBLE 1:1d4bd90af0e4
  M a
  ACTUAL  0:80971e65b431
  M a
  ====
  committing files:
  a
  committing manifest
  committing changelog
  created 6d019af21222
  applying ../patch3
  patching file foo
  adding foo
  ====
  VISIBLE 2:6d019af21222
  A foo
  ACTUAL  0:80971e65b431
  M a
  ====
  committing files:
  foo
  committing manifest
  committing changelog
  created 55e3f75b2378

  $ hg --cwd b rollback -q

(content of file "a" is already changed and it should be recognized as
"M", even though dirstate is restored to one before "hg import")

  $ (cd b && sh "$TESTTMP/checkvisibility.sh")
  ====
  VISIBLE 0:80971e65b431
  M a
  ACTUAL  0:80971e65b431
  M a
  ====
  $ hg --cwd b revert --no-backup a
  $ rm -f b/foo

== test visibility to precommit external hook

  $ cat >> b/.hg/hgrc <<EOF
  > [hooks]
  > precommit.visibility = sh $TESTTMP/checkvisibility.sh
  > EOF

  $ (cd b && sh "$TESTTMP/checkvisibility.sh")
  ====
  VISIBLE 0:80971e65b431
  ACTUAL  0:80971e65b431
  ====

  $ hg --cwd b import ../patch1 ../patch2 ../patch3
  applying ../patch1
  ====
  VISIBLE 0:80971e65b431
  M a
  ACTUAL  0:80971e65b431
  M a
  ====
  applying ../patch2
  ====
  VISIBLE 1:1d4bd90af0e4
  M a
  ACTUAL  0:80971e65b431
  M a
  ====
  applying ../patch3
  ====
  VISIBLE 2:6d019af21222
  A foo
  ACTUAL  0:80971e65b431
  M a
  ====

  $ hg --cwd b rollback -q
  $ (cd b && sh "$TESTTMP/checkvisibility.sh")
  ====
  VISIBLE 0:80971e65b431
  M a
  ACTUAL  0:80971e65b431
  M a
  ====
  $ hg --cwd b revert --no-backup a
  $ rm -f b/foo

  $ cat >> b/.hg/hgrc <<EOF
  > [hooks]
  > precommit.visibility =
  > EOF

== test visibility to pretxncommit external hook

  $ cat >> b/.hg/hgrc <<EOF
  > [hooks]
  > pretxncommit.visibility = sh $TESTTMP/checkvisibility.sh
  > EOF

  $ (cd b && sh "$TESTTMP/checkvisibility.sh")
  ====
  VISIBLE 0:80971e65b431
  ACTUAL  0:80971e65b431
  ====

  $ hg --cwd b import ../patch1 ../patch2 ../patch3
  applying ../patch1
  ====
  VISIBLE 0:80971e65b431
  M a
  ACTUAL  0:80971e65b431
  M a
  ====
  applying ../patch2
  ====
  VISIBLE 1:1d4bd90af0e4
  M a
  ACTUAL  0:80971e65b431
  M a
  ====
  applying ../patch3
  ====
  VISIBLE 2:6d019af21222
  A foo
  ACTUAL  0:80971e65b431
  M a
  ====

  $ hg --cwd b rollback -q
  $ (cd b && sh "$TESTTMP/checkvisibility.sh")
  ====
  VISIBLE 0:80971e65b431
  M a
  ACTUAL  0:80971e65b431
  M a
  ====
  $ hg --cwd b revert --no-backup a
  $ rm -f b/foo

  $ cat >> b/.hg/hgrc <<EOF
  > [hooks]
  > pretxncommit.visibility =
  > EOF

Nicolas Dumazet's avatar
Nicolas Dumazet committed
  $ rm -r b


importing a patch in a subdirectory failed at the commit stage

  $ echo line 2 >> a/d1/d2/a
  $ hg --cwd a ci -u someoneelse -d '1 0' -m'subdir change'

hg import in a subdirectory

  $ hg clone -r0 a b
  adding changesets
  adding manifests
  adding file changes
  added 1 changesets with 2 changes to 2 files
  updating to branch default
  2 files updated, 0 files merged, 0 files removed, 0 files unresolved
  $ hg --cwd a export tip > tmp
  $ sed -e 's/d1\/d2\///' < tmp > subdir-tip.patch
Nicolas Dumazet's avatar
Nicolas Dumazet committed
  $ dir=`pwd`
  $ cd b/d1/d2 2>&1 > /dev/null
  $ hg import  ../../../subdir-tip.patch
  applying ../../../subdir-tip.patch
Nicolas Dumazet's avatar
Nicolas Dumazet committed
  $ cd "$dir"

message should be 'subdir change'
committer should be 'someoneelse'

  $ hg --cwd b tip
  changeset:   1:3577f5aea227
  tag:         tip
Nicolas Dumazet's avatar
Nicolas Dumazet committed
  user:        someoneelse
  date:        Thu Jan 01 00:00:01 1970 +0000
  summary:     subdir change
  
Nicolas Dumazet's avatar
Nicolas Dumazet committed

should be empty

  $ hg --cwd b status


Test fuzziness (ambiguous patch location, fuzz=2)

  $ hg init fuzzy
  $ cd fuzzy
  $ echo line1 > a
  $ echo line0 >> a
  $ echo line3 >> a
  $ hg ci -Am adda
  adding a
  $ echo line1 > a
  $ echo line2 >> a
  $ echo line0 >> a
  $ echo line3 >> a
  $ hg ci -m change a
Nicolas Dumazet's avatar
Nicolas Dumazet committed
  $ hg up -C 0
  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
  $ echo line1 > a
  $ echo line0 >> a
  $ echo line1 >> a
  $ echo line0 >> a
  $ hg ci -m brancha
  created new head
  $ hg import --config patch.fuzz=0 -v fuzzy-tip.patch
  applying fuzzy-tip.patch
  patching file a
  Hunk #1 FAILED at 0
  1 out of 1 hunks FAILED -- saving rejects to file a.rej
  abort: patch failed to apply
  [255]
  $ hg import --no-commit -v fuzzy-tip.patch
  applying fuzzy-tip.patch
Nicolas Dumazet's avatar
Nicolas Dumazet committed
  patching file a
  Hunk #1 succeeded at 2 with fuzz 1 (offset 0 lines).
Nicolas Dumazet's avatar
Nicolas Dumazet committed
  $ hg revert -a
  reverting a


import with --no-commit should have written .hg/last-message.txt

  $ cat .hg/last-message.txt
  change (no-eol)
Nicolas Dumazet's avatar
Nicolas Dumazet committed
test fuzziness with eol=auto

  $ hg --config patch.eol=auto import --no-commit -v fuzzy-tip.patch
  applying fuzzy-tip.patch
Nicolas Dumazet's avatar
Nicolas Dumazet committed
  patching file a
  Hunk #1 succeeded at 2 with fuzz 1 (offset 0 lines).
Nicolas Dumazet's avatar
Nicolas Dumazet committed
  $ cd ..


Test hunk touching empty files (issue906)

  $ hg init empty
  $ cd empty
  $ touch a
  $ touch b1
  $ touch c1
  $ echo d > d
  $ hg ci -Am init
  adding a
  adding b1
  adding c1
  adding d
  $ echo a > a
  $ echo b > b1
  $ hg mv b1 b2
  $ echo c > c1
  $ hg copy c1 c2
  $ rm d
  $ touch d
  $ hg diff --git
  diff --git a/a b/a
  --- a/a
  +++ b/a
  @@ -0,0 +1,1 @@
  +a
  diff --git a/b1 b/b2
  rename from b1
  rename to b2
  --- a/b1
  +++ b/b2
  @@ -0,0 +1,1 @@
  +b
  diff --git a/c1 b/c1
  --- a/c1
  +++ b/c1
  @@ -0,0 +1,1 @@
  +c
  diff --git a/c1 b/c2
  copy from c1
  copy to c2
  --- a/c1
  +++ b/c2
  @@ -0,0 +1,1 @@
  +c
  diff --git a/d b/d
  --- a/d
  +++ b/d
  @@ -1,1 +0,0 @@
  -d
  $ hg ci -m empty
  $ hg export --git tip > empty.diff
  $ hg up -C 0
  4 files updated, 0 files merged, 2 files removed, 0 files unresolved
  $ hg import empty.diff
  applying empty.diff
  $ for name in a b1 b2 c1 c2 d; do
  >   echo % $name file
  >   test -f $name && cat $name
  >   done
  % a file
  a
  % b1 file
  % b2 file
  b
  % c1 file
  c
  % c2 file
  c
  % d file
  $ cd ..


Test importing a patch ending with a binary file removal

  $ hg init binaryremoval
  $ cd binaryremoval
  $ echo a > a
  $ $PYTHON -c "file('b', 'wb').write('a\x00b')"
Nicolas Dumazet's avatar
Nicolas Dumazet committed
  $ hg ci -Am addall
  adding a
  adding b
  $ hg rm a
  $ hg rm b
  $ hg st
  R a
  R b
  $ hg ci -m remove
  $ hg export --git . > remove.diff
  $ cat remove.diff | grep git
  diff --git a/a b/a
  diff --git a/b b/b
  $ hg up -C 0
  2 files updated, 0 files merged, 0 files removed, 0 files unresolved
  $ hg import remove.diff
  applying remove.diff
  $ hg manifest
  $ cd ..


Issue927: test update+rename with common name
Nicolas Dumazet's avatar
Nicolas Dumazet committed

  $ hg init t
  $ cd t
  $ touch a
  $ hg ci -Am t
  adding a
  $ echo a > a

Here, bfile.startswith(afile)

  $ hg copy a a2
  $ hg ci -m copya
  $ hg export --git tip > copy.diff
  $ hg up -C 0
  1 files updated, 0 files merged, 1 files removed, 0 files unresolved
  $ hg import copy.diff
  applying copy.diff

a should contain an 'a'

  $ cat a
  a

and a2 should have duplicated it

  $ cat a2
  a
  $ cd ..


test -p0

  $ hg init p0
  $ cd p0
  $ echo a > a
  $ hg ci -Am t
  adding a
  $ hg import -p foo
  abort: invalid value 'foo' for option -p, expected int
  [255]
Nicolas Dumazet's avatar
Nicolas Dumazet committed
  $ hg import -p0 - << EOF
  > foobar
  > --- a	Sat Apr 12 22:43:58 2008 -0400
  > +++ a	Sat Apr 12 22:44:05 2008 -0400
  > @@ -1,1 +1,1 @@
  > -a
  > +bb
  > EOF
  applying patch from stdin
  $ 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
Nicolas Dumazet's avatar
Nicolas Dumazet committed
  $ cd ..


test paths outside repo root

  $ mkdir outside
  $ touch outside/foo
  $ hg init inside
  $ cd inside
  $ hg import - <<EOF
  > diff --git a/a b/b
  > rename from ../outside/foo
  > rename to bar
  > EOF
  applying patch from stdin
  abort: path contains illegal component: ../outside/foo (glob)
Nicolas Dumazet's avatar
Nicolas Dumazet committed
  $ cd ..


test import with similarity and git and strip (issue295 et al.)

  $ hg init sim
  $ cd sim
  $ echo 'this is a test' > a
  $ hg ci -Ama
  adding a
  $ cat > ../rename.diff <<EOF
  > diff --git a/foo/a b/foo/a
  > deleted file mode 100644
  > --- a/foo/a
  > +++ /dev/null
  > @@ -1,1 +0,0 @@
  > -this is a test
  > diff --git a/foo/b b/foo/b
  > new file mode 100644
  > --- /dev/null
  > +++ b/foo/b
  > @@ -0,0 +1,2 @@
  > +this is a test
  > +foo
  > EOF
  $ hg import --no-commit -v -s 1 ../rename.diff -p2
  applying ../rename.diff
  patching file a
  patching file b
  adding b
  recording removal of a as rename to b (88% similar)
Nicolas Dumazet's avatar
Nicolas Dumazet committed
  $ hg st -C
  A b
    a
  R a
  $ hg revert -a
  undeleting a
  forgetting b
  $ rm b
  $ hg import --no-commit -v -s 100 ../rename.diff -p2
  applying ../rename.diff
  patching file a
  patching file b
  adding b
Nicolas Dumazet's avatar
Nicolas Dumazet committed
  $ hg st -C
  A b
  R a
  $ cd ..


Issue1495: add empty file from the end of patch
Nicolas Dumazet's avatar
Nicolas Dumazet committed

  $ hg init addemptyend
  $ cd addemptyend
  $ touch a
  $ hg addremove
  adding a
  $ hg ci -m "commit"
  $ cat > a.patch <<EOF
Nicolas Dumazet's avatar
Nicolas Dumazet committed
  > diff --git a/a b/a
  > --- a/a
  > +++ b/a
  > @@ -0,0 +1,1 @@
  > +a
  > diff --git a/b b/b
  > new file mode 100644
  > EOF
  $ hg import --no-commit a.patch
  applying a.patch

apply a good patch followed by an empty patch (mainly to ensure
that dirstate is *not* updated when import crashes)