git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Stephan Beyer <s-beyer@gmx.net>
To: git@vger.kernel.org
Cc: gitster@pobox.com
Subject: [PATCH] Add test cases for git-am
Date: Fri, 30 May 2008 16:04:47 +0200	[thread overview]
Message-ID: <20080530140447.GB10514@leksak.fem-net> (raw)

Add t/t4151-am.sh that does basic testing of git-am functionality,
including:
 * am applies patch correctly
 * am changes committer and keeps author
 * am --signoff adds Signed-off-by: line
 * am stays in branch
 * am --signoff does not add Signed-off-by: line if already there
 * am without --keep removes Re: and [PATCH] stuff
 * am --keep really keeps the subject
 * am -3 falls back to 3-way merge
 * am pauses on conflict
 * am --skip works
 * am --resolved works
 * am takes patches from a Pine mailbox
 * am fails on mail without patch
 * am fails on empty patch

Signed-off-by: Stephan Beyer <s-beyer@gmx.net>
---
Hi,

the reason I added this test is because I'm working on git-sequencer (for
GSoC'08), which functions as a common backend for git-am, git-rebase, ...
And I think this test will make my life easier ;-)

As this is my first test, I hope to get some constructive feedback.

Perhaps it is also useful to swap t4150 and t4151 or to merge them.

Ah, and I omitted tests for --whitespace and some other git-apply-specific
stuff.

Regards,
  Stephan

 t/t4151-am.sh |  223 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 223 insertions(+), 0 deletions(-)
 create mode 100755 t/t4151-am.sh

diff --git a/t/t4151-am.sh b/t/t4151-am.sh
new file mode 100755
index 0000000..df4fb5a
--- /dev/null
+++ b/t/t4151-am.sh
@@ -0,0 +1,223 @@
+#!/bin/sh
+
+test_description='git am running'
+
+. ./test-lib.sh
+
+cat >msg <<EOF
+second
+
+Lorem ipsum dolor sit amet, consectetuer sadipscing elitr, sed diam nonumy
+eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam
+voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita
+kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem
+ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod
+tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At
+vero eos et accusam et justo duo dolores et ea rebum.
+
+	Duis autem vel eum iriure dolor in hendrerit in vulputate velit
+	esse molestie consequat, vel illum dolore eu feugiat nulla facilisis
+	at vero eros et accumsan et iusto odio dignissim qui blandit
+	praesent luptatum zzril delenit augue duis dolore te feugait nulla
+	facilisi.
+
+
+Lorem ipsum dolor sit amet,
+consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut
+laoreet dolore magna aliquam erat volutpat.
+
+  git
+  ---
+  +++
+
+Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit
+lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure
+dolor in hendrerit in vulputate velit esse molestie consequat, vel illum
+dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio
+dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te
+feugait nulla facilisi.
+EOF
+
+cat >failmail <<EOF
+From foo@example.com Fri May 23 10:43:49 2008
+From:	foo@example.com
+To:	bar@example.com
+Subject: Re: [RFC/PATCH] git-foo.sh
+Date:	Fri, 23 May 2008 05:23:42 +0200
+
+Sometimes we have to find out that there's nothing left.
+
+EOF
+
+cat >pine <<EOF
+From MAILER-DAEMON Fri May 23 10:43:49 2008
+Date: 23 May 2008 05:23:42 +0200
+From: Mail System Internal Data <MAILER-DAEMON@example.com>
+Subject: DON'T DELETE THIS MESSAGE -- FOLDER INTERNAL DATA
+Message-ID: <foo-0001@example.com>
+
+This text is part of the internal format of your mail folder, and is not
+a real message.  It is created automatically by the mail system software.
+If deleted, important folder data will be lost, and it will be re-created
+with the data reset to initial values.
+
+EOF
+
+test_expect_success setup '
+	echo hello >file &&
+	git add file &&
+	test_tick &&
+	git commit -m first &&
+	git tag first &&
+	echo world >>file &&
+	git add file &&
+	test_tick &&
+	git commit -s -F msg &&
+	git tag second &&
+	git format-patch --stdout first >patch1 &&
+	tail -n +3 msg >file &&
+	git add file &&
+	test_tick &&
+	git commit -m third &&
+	git tag third &&
+	git format-patch --stdout first >patch2	&&
+	git checkout -b lorem &&
+	tail -n +11 msg >file &&
+	head -n +9 msg >>file &&
+	test_tick &&
+	git commit -a -m "moved stuff" &&
+	echo goodbye >another &&
+	git add another &&
+	test_tick &&
+	git commit -m "added another file" &&
+	git format-patch --stdout master >lorem-move.patch
+'
+
+# reset time
+unset test_tick
+test_tick
+
+test_expect_success 'am applies patch correctly' '
+	git checkout first &&
+	test_tick &&
+	git am <patch1 &&
+	! test -d .dotest &&
+	test -z "$(git diff second)" &&
+	test "$(git rev-parse second)" = "$(git rev-parse HEAD)" &&
+	test "$(git rev-parse second^)" = "$(git rev-parse HEAD^)"
+'
+
+GIT_AUTHOR_NAME="Another Thor"
+GIT_AUTHOR_EMAIL="a.thor@example.com"
+GIT_COMMITTER_NAME="Co M Miter" 
+GIT_COMMITTER_EMAIL="c.miter@example.com"
+export GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL GIT_COMMITTER_NAME GIT_COMMITTER_EMAIL
+
+compare () {
+	test "$(git cat-file commit "$2" | grep "^$1 ")" = \
+	     "$(git cat-file commit "$3" | grep "^$1 ")"
+}
+
+test_expect_success 'am changes committer and keeps author' '
+	test_tick &&
+	git checkout first &&
+	git am patch2 &&
+	! test -d .dotest &&
+	test "$(git rev-parse master)" != "$(git rev-parse HEAD)" &&
+	test "$(git rev-parse master^)" != "$(git rev-parse HEAD^)" &&
+	test "$(git rev-parse master^^)" = "$(git rev-parse HEAD^^)" &&
+	test -z "$(git diff master..HEAD)" &&
+	test -z "$(git diff master^..HEAD^)" &&
+	compare author master HEAD &&
+	compare author master^ HEAD^ &&
+	! compare committer master HEAD &&
+	! compare committer master^ HEAD^
+'
+
+test_expect_success 'am --signoff adds Signed-off-by: line' '
+	git checkout -b master2 first &&
+	git am --signoff <patch2 &&
+	test "$(git cat-file commit HEAD | grep -c "^Signed-off-by:")" -eq 1 &&
+	test "$(git cat-file commit HEAD^ | grep -c "^Signed-off-by:")" -eq 2
+'
+
+test_expect_success 'am stays in branch' '
+	test "refs/heads/master2" = "$(git symbolic-ref HEAD)"
+'
+
+test_expect_success 'am --signoff does not add Signed-off-by: line if already there' '
+	git format-patch --stdout HEAD^ >patch3 &&
+	sed -e "/^Subject/ s,\[PATCH,Re: Re: Re: & 1/5 v2," patch3 >patch4
+	git checkout HEAD^ &&
+	git am --signoff patch4 &&
+	test "$(git cat-file commit HEAD | grep -c "^Signed-off-by:")" -eq 1
+'
+
+test_expect_success 'am without --keep removes Re: and [PATCH] stuff' '
+	test "$(git rev-parse HEAD)" = "$(git rev-parse master2)"
+'
+
+test_expect_success 'am --keep really keeps the subject' '
+	git checkout HEAD^ &&
+	git am --keep patch4 &&
+	! test -d .dotest &&
+	git-cat-file commit HEAD |
+		grep -q -F "Re: Re: Re: [PATCH 1/5 v2] third"
+'
+
+test_expect_success 'am -3 falls back to 3-way merge' '
+	git checkout -b lorem2 master2 &&
+	tail -n +3 msg >file &&
+	head -n +9 msg >>file &&
+	git add file &&
+	test_tick &&
+	git commit -m "copied stuff" &&
+	git am -3 lorem-move.patch &&
+	! test -d .dotest &&
+	test -z "$(git diff lorem)"
+'
+
+test_expect_success 'am pauses on conflict' '
+	git checkout lorem2^^ &&
+	! git am lorem-move.patch &&
+	test -d .dotest
+'
+
+test_expect_success 'am --skip works' '
+	git am --skip &&
+	! test -d .dotest &&
+	test -z "$(git diff lorem2^^ -- file)" &&
+	test goodbye = "$(cat another)"
+'
+
+test_expect_success 'am --resolved works' '
+	git checkout lorem2^^ &&
+	! git am lorem-move.patch &&
+	test -d .dotest &&
+	echo resolved >>file &&
+	git add file &&
+	git am --resolved &&
+	! test -d .dotest &&
+	test goodbye = "$(cat another)"
+'
+
+test_expect_success 'am takes patches from a Pine mailbox' '
+	git checkout first &&
+	cat pine patch1 | git am &&
+	! test -d .dotest &&
+	test -z "$(git diff master^..HEAD)"
+'
+
+test_expect_success 'am fails on mail without patch' '
+	! git am <failmail &&
+	rm -r .dotest/
+'
+
+test_expect_success 'am fails on empty patch' '
+	echo "---" >>failmail &&
+	! git am <failmail &&
+	git am --skip &&
+	! test -d .dotest
+'
+
+test_done
-- 
Stephan Beyer <s-beyer@gmx.net>, PGP 0x6EDDD207FCC5040F

             reply	other threads:[~2008-05-30 14:05 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-05-30 14:04 Stephan Beyer [this message]
2008-05-30 22:12 ` [PATCH] Add test cases for git-am Junio C Hamano
2008-05-31  2:40   ` Stephan Beyer
2008-05-31  6:26     ` Mutt and Mail-Followup-To Teemu Likonen
2008-05-31 19:22     ` [PATCH] Add test cases for git-am Junio C Hamano
2008-05-31 22:07       ` Stephan Beyer
2008-05-31 22:11         ` [PATCH v2 1/2] " Stephan Beyer
2008-05-31 22:11           ` [PATCH v2 2/2] Merge t4150-am-subdir.sh and t4151-am.sh into t4150-am.sh Stephan Beyer
2008-05-31 22:41         ` [PATCH] Add test cases for git-am Junio C Hamano
2008-06-02 17:53         ` Andreas Ericsson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20080530140447.GB10514@leksak.fem-net \
    --to=s-beyer@gmx.net \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).