Signed-off-by: Avery Pennarun <apenwarr@xxxxxxxxx> --- 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 -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html