git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Avery Pennarun <apenwarr@gmail.com>
To: git@vger.kernel.org
Cc: gitster@pobox.com, Avery Pennarun <apenwarr@gmail.com>
Subject: [PATCH v2 3/3] filter-branch --blob-filter: add tests.
Date: Thu, 12 Jun 2008 20:52:24 -0400	[thread overview]
Message-ID: <1213318344-26013-3-git-send-email-apenwarr@gmail.com> (raw)
In-Reply-To: <1213318344-26013-2-git-send-email-apenwarr@gmail.com>

Signed-off-by: Avery Pennarun <apenwarr@gmail.com>
---
 t/t7003-filter-branch-blob.sh |   94 +++++++++++++++++++++++++++++++++++++++++
 1 files changed, 94 insertions(+), 0 deletions(-)
 create mode 100755 t/t7003-filter-branch-blob.sh

diff --git a/t/t7003-filter-branch-blob.sh b/t/t7003-filter-branch-blob.sh
new file mode 100755
index 0000000..f18031e
--- /dev/null
+++ b/t/t7003-filter-branch-blob.sh
@@ -0,0 +1,94 @@
+#!/bin/sh
+
+test_description='git-filter-branch --blob-filter'
+. ./test-lib.sh
+
+make_commit () {
+	echo -n "$2" >"$1"
+	git add "$1"
+	git commit -a -m "$1"
+}
+
+match_file() {
+	f="$(cat "$1")"
+	echo "'$f'" = "'$2'"
+	test "$f" = "$2"
+}
+
+myfilter() {
+	git-filter-branch --blob-filter 'case "$GIT_BLOB_PATH" in '"$1"') echo -n REPLACEMENT;; *) cat;; esac' HEAD &&
+	rm -rf .git/refs/original
+}
+
+test_expect_success 'setup' '
+	make_commit A "textA" &&
+	make_commit "Space file" "Space text" &&
+	make_commit B.txt "textB" &&
+	make_commit C.jpg "jpgC" &&
+	git checkout -b caching &&
+	make_commit AA "textA" &&
+	make_commit A "textA2" &&
+	git checkout -b renames master &&
+	mkdir dir &&
+	rm -f B.txt &&
+	make_commit dir/B.jpg "textB" &&
+	rm -f C.jpg &&
+	make_commit dir/C.txt "jpgC"
+'
+
+test_expect_success 'rewrite all' '
+	git checkout -b rewrite1 master &&
+	git-filter-branch --blob-filter echo\ -n\ \$GIT_BLOB_PATH HEAD
+	rm -rf .git/refs/original
+'
+
+test_expect_success 'rewrite all - result' '
+	match_file A "A" &&
+	match_file "Space file" "Space file" &&
+	match_file B.txt "B.txt" &&
+	match_file C.jpg "C.jpg"
+'
+
+countfilter() {
+	rm -f counter
+	export P="$PWD"
+	git-filter-branch --blob-filter 'echo tick >>$P/counter; echo -n $GIT_BLOB_PATH' HEAD &&
+	rm -rf .git/refs/original
+}
+
+test_expect_success 'caching' '
+	git checkout -b rewrite1b caching &&
+	countfilter
+'
+
+test_expect_success 'caching - result' '
+	match_file A "A" &&
+	match_file AA "AA" &&
+	match_file B.txt "B.txt" &&
+	match_file C.jpg "C.jpg" &&
+	test "$(cat counter | wc -l)" = 6
+'
+
+test_expect_success 'rewrite .txt only' '
+	git checkout -b rewrite2 master &&
+	myfilter \*.txt
+'
+
+test_expect_success 'rewrite .txt only - result' '
+	match_file A "textA" &&
+	match_file B.txt "REPLACEMENT" &&
+	match_file C.jpg "jpgC"
+'
+
+test_expect_success 'rewrite with renames' '
+	git checkout -b rewrite3 renames &&
+	myfilter \*.txt
+'
+
+test_expect_success 'rewrite with renames - result' '
+	match_file A "textA" &&
+	match_file dir/B.jpg "textB" &&
+	match_file dir/C.txt "REPLACEMENT"
+'
+
+test_done
-- 
1.5.6.rc2.29.g4717e

  reply	other threads:[~2008-06-13  1:04 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-06-13  0:52 [PATCH v2 1/3] filter-branch: add new --blob-filter option Avery Pennarun
2008-06-13  0:52 ` [PATCH v2 2/3] filter-branch --blob-filter: speed/flexibility improvements Avery Pennarun
2008-06-13  0:52   ` Avery Pennarun [this message]
2008-06-13  6:25 ` [PATCH v2 1/3] filter-branch: add new --blob-filter option Jeff King
2008-06-13 16:10   ` Avery Pennarun

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

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

  git send-email \
    --in-reply-to=1213318344-26013-3-git-send-email-apenwarr@gmail.com \
    --to=apenwarr@gmail.com \
    --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.
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 NNTP newsgroup(s).