--- /dev/null
+#!/bin/sh
+# Copyright (c) 2006 Karl Hasselström
+test_description='Test the import command'
+. ./test-lib.sh
+
+test_expect_success \
+ 'Initialize the StGIT repository' \
+ '
+ for x in {do,di,da}{be,bi,bo}{dam,dim,dum}; do
+ echo $x
+ done > foo.txt &&
+ git add foo.txt &&
+ git commit -a -m "initial version" &&
+ stg init
+ '
+
+test_expect_success \
+ 'Apply a patch created with "git diff"' \
+ '
+ stg import ../t1800-import/git-diff &&
+ [ $(git cat-file -p $(stg id) \
+ | grep -c "tree e96b1fba2160890ff600b675d7140d46b022b155") == 1 ] &&
+ stg delete ..
+ '
+
+test_expect_success \
+ 'Apply a patch created with GNU diff' \
+ '
+ stg import ../t1800-import/gnu-diff &&
+ [ $(git cat-file -p $(stg id) \
+ | grep -c "tree e96b1fba2160890ff600b675d7140d46b022b155") == 1 ] &&
+ stg delete ..
+ '
+
+test_expect_success \
+ 'Apply a patch created with "stg export"' \
+ '
+ stg import ../t1800-import/stg-export &&
+ [ $(git cat-file -p $(stg id) \
+ | grep -c "tree e96b1fba2160890ff600b675d7140d46b022b155") == 1 ] &&
+ stg delete ..
+ '
+
+test_expect_success \
+ 'Apply a patch from an 8bit-encoded e-mail' \
+ '
+ stg import -m ../t1800-import/email-8bit &&
+ [ $(git cat-file -p $(stg id) \
+ | grep -c "tree 030be42660323ff2a1958f9ee79589a4f3fbee2f") == 1 ] &&
+ [ $(git cat-file -p $(stg id) \
+ | grep -c "author Inge Ström <inge@power.com>") == 1 ] &&
+ stg delete ..
+ '
+
+test_expect_success \
+ 'Apply a patch from a QP-encoded e-mail' \
+ '
+ stg import -m ../t1800-import/email-qp &&
+ [ $(git cat-file -p $(stg id) \
+ | grep -c "tree 030be42660323ff2a1958f9ee79589a4f3fbee2f") == 1 ] &&
+ [ $(git cat-file -p $(stg id) \
+ | grep -c "author Inge Ström <inge@power.com>") == 1 ] &&
+ stg delete ..
+ '
+
+test_expect_success \
+ 'Apply several patches from an mbox file' \
+ '
+ stg import -M ../t1800-import/email-mbox &&
+ [ $(git cat-file -p $(stg id change-1) \
+ | grep -c "tree 401bef82cd9fb403aba18f480a63844416a2e023") == 1 ] &&
+ [ $(git cat-file -p $(stg id change-1) \
+ | grep -c "author Inge Ström <inge@power.com>") == 1 ] &&
+ [ $(git cat-file -p $(stg id change-2) \
+ | grep -c "tree e49dbce010ec7f441015a8c64bce0b99108af4cc") == 1 ] &&
+ [ $(git cat-file -p $(stg id change-2) \
+ | grep -c "author Inge Ström <inge@power.com>") == 1 ] &&
+ [ $(git cat-file -p $(stg id change-3) \
+ | grep -c "tree 166bbaf27a44aee21ba78c98822a741e6f7d78f5") == 1 ] &&
+ [ $(git cat-file -p $(stg id change-3) \
+ | grep -c "author Inge Ström <inge@power.com>") == 1 ] &&
+ stg delete ..
+ '
+
+test_done
--- /dev/null
+From: Inge =?utf-8?q?Str=C3=B6m?= <inge@power.com>
+Subject: [PATCH] test patch
+To: Upstream <foo@bar.baz>
+Date: Sat, 11 Nov 2006 11:58:14 +0100
+Message-ID: <20061111105814.23209.46952.stgit@localhost>
+User-Agent: StGIT/0.11
+MIME-Version: 1.0
+Content-Type: text/plain; charset="utf-8"
+Content-Transfer-Encoding: 8bit
+
+Signed-off-by: Inge Ström <inge@power.com>
+---
+
+ foo.txt | 2 ++
+ 1 files changed, 2 insertions(+), 0 deletions(-)
+
+diff --git a/foo.txt b/foo.txt
+index ad01662..d3cd5b6 100644
+--- a/foo.txt
++++ b/foo.txt
+@@ -3,6 +3,7 @@ dobedim
+ dobedum
+ dobidam
+ dobidim
++pum-pöddelipåm
+ dobidum
+ dobodam
+ dobodim
+@@ -20,6 +21,7 @@ dabedam
+ dabedim
+ dabedum
+ dabidam
++pum-däddelidum
+ dabidim
+ dabidum
+ dabodam
+
--- /dev/null
+From nobody Sat Nov 11 12:45:27 2006
+From: Inge =?utf-8?q?Str=C3=B6m?= <inge@power.com>
+Subject: [PATCH 1/3] Change 1
+To: Upstream <foo@bar.baz>
+Date: Sat, 11 Nov 2006 12:45:27 +0100
+Message-ID: <20061111114527.31778.12942.stgit@localhost>
+User-Agent: StGIT/0.11
+MIME-Version: 1.0
+Content-Type: text/plain; charset="utf-8"
+Content-Transfer-Encoding: 8bit
+Status: RO
+Content-Length: 304
+Lines: 19
+
+Signed-off-by: Inge Ström <inge@power.com>
+---
+
+ foo.txt | 2 +-
+ 1 files changed, 1 insertions(+), 1 deletions(-)
+
+diff --git a/foo.txt b/foo.txt
+index ad01662..91527b1 100644
+--- a/foo.txt
++++ b/foo.txt
+@@ -7,7 +7,7 @@ dobidum
+ dobodam
+ dobodim
+ dobodum
+-dibedam
++dibedad
+ dibedim
+ dibedum
+ dibidam
+
+From nobody Sat Nov 11 12:45:27 2006
+From: Inge =?utf-8?q?Str=C3=B6m?= <inge@power.com>
+Subject: [PATCH 2/3] Change 2
+To: Upstream <foo@bar.baz>
+Date: Sat, 11 Nov 2006 12:45:27 +0100
+Message-ID: <20061111114527.31778.92851.stgit@localhost>
+In-Reply-To: <20061111114527.31778.12942.stgit@localhost>
+References: <20061111114527.31778.12942.stgit@localhost>
+User-Agent: StGIT/0.11
+MIME-Version: 1.0
+Content-Type: text/plain; charset="utf-8"
+Content-Transfer-Encoding: 8bit
+Status: RO
+Content-Length: 296
+Lines: 18
+
+Signed-off-by: Inge Ström <inge@power.com>
+---
+
+ foo.txt | 1 +
+ 1 files changed, 1 insertions(+), 0 deletions(-)
+
+diff --git a/foo.txt b/foo.txt
+index 91527b1..79922d7 100644
+--- a/foo.txt
++++ b/foo.txt
+@@ -18,6 +18,7 @@ dibodim
+ dibodum
+ dabedam
+ dabedim
++dibedam
+ dabedum
+ dabidam
+ dabidim
+
+From nobody Sat Nov 11 12:45:27 2006
+From: Inge =?utf-8?q?Str=C3=B6m?= <inge@power.com>
+Subject: [PATCH 3/3] Change 3
+To: Upstream <foo@bar.baz>
+Date: Sat, 11 Nov 2006 12:45:27 +0100
+Message-ID: <20061111114527.31778.45876.stgit@localhost>
+In-Reply-To: <20061111114527.31778.12942.stgit@localhost>
+References: <20061111114527.31778.12942.stgit@localhost>
+User-Agent: StGIT/0.11
+MIME-Version: 1.0
+Content-Type: text/plain; charset="utf-8"
+Content-Transfer-Encoding: 8bit
+Status: RO
+Content-Length: 278
+Lines: 16
+
+Signed-off-by: Inge Ström <inge@power.com>
+---
+
+ foo.txt | 1 -
+ 1 files changed, 0 insertions(+), 1 deletions(-)
+
+diff --git a/foo.txt b/foo.txt
+index 79922d7..6f978b4 100644
+--- a/foo.txt
++++ b/foo.txt
+@@ -24,5 +24,4 @@ dabidam
+ dabidim
+ dabidum
+ dabodam
+-dabodim
+ dabodum
+
--- /dev/null
+From: Inge =?utf-8?q?Str=C3=B6m?= <inge@power.com>
+Subject: [PATCH] test patch
+To: Upstream <foo@bar.baz>
+Date: Sat, 11 Nov 2006 11:58:14 +0100
+Message-ID: <20061111105814.23209.46952.stgit@localhost>
+User-Agent: StGIT/0.11
+MIME-Version: 1.0
+Content-Type: text/plain; charset="utf-8"
+Content-Transfer-Encoding: quoted-printable
+
+Signed-off-by: Inge Str=C3=B6m <inge@power.com>
+---
+
+ foo.txt | 2 ++
+ 1 files changed, 2 insertions(+), 0 deletions(-)
+
+diff --git a/foo.txt b/foo.txt
+index ad01662..d3cd5b6 100644
+--- a/foo.txt
++++ b/foo.txt
+@@ -3,6 +3,7 @@ dobedim
+ dobedum
+ dobidam
+ dobidim
++pum-p=C3=B6ddelip=C3=A5m
+ dobidum
+ dobodam
+ dobodim
+@@ -20,6 +21,7 @@ dabedam
+ dabedim
+ dabedum
+ dabidam
++pum-d=C3=A4ddelidum
+ dabidim
+ dabidum
+ dabodam
+
--- /dev/null
+diff --git a/foo.txt b/foo.txt
+index ad01662..d3cd5b6 100644
+--- a/foo.txt
++++ b/foo.txt
+@@ -3,6 +3,7 @@ dobedim
+ dobedum
+ dobidam
+ dobidim
++dabadadash
+ dobidum
+ dobodam
+ dobodim
+@@ -20,6 +21,7 @@ dabedam
+ dabedim
+ dabedum
+ dabidam
++dadadadash
+ dabidim
+ dabidum
+ dabodam
--- /dev/null
+diff -Naur old/foo.txt new/foo.txt
+--- old/foo.txt 2006-11-11 11:26:18.000000000 +0100
++++ new/foo.txt 2006-11-11 11:25:18.000000000 +0100
+@@ -3,6 +3,7 @@
+ dobedum
+ dobidam
+ dobidim
++dabadadash
+ dobidum
+ dobodam
+ dobodim
+@@ -20,6 +21,7 @@
+ dabedim
+ dabedum
+ dabidam
++dadadadash
+ dabidim
+ dabidum
+ dabodam
--- /dev/null
+test patch
+---
+
+ foo.txt | 2 ++
+ 1 files changed, 2 insertions(+), 0 deletions(-)
+
+diff --git a/foo.txt b/foo.txt
+index ad01662..d3cd5b6 100644
+--- a/foo.txt
++++ b/foo.txt
+@@ -3,6 +3,7 @@ dobedim
+ dobedum
+ dobidam
+ dobidim
++dabadadash
+ dobidum
+ dobodam
+ dobodim
+@@ -20,6 +21,7 @@ dabedam
+ dabedim
+ dabedum
+ dabidam
++dadadadash
+ dabidim
+ dabidum
+ dabodam