t1007: factor out repeated setup
authorJeff King <peff@peff.net>
Tue, 13 Sep 2016 03:23:12 +0000 (20:23 -0700)
committerJunio C Hamano <gitster@pobox.com>
Tue, 13 Sep 2016 22:45:45 +0000 (15:45 -0700)
We have a series of 3 CRLF tests that do exactly the same
(long) setup sequence. Let's pull it out into a common setup
test, which is shorter, more efficient, and will make it
easier to add new tests.

Note that we don't have to worry about cleaning up any of
the setup which was previously per-test; we call pop_repo
after the CRLF tests, which cleans up everything.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
t/t1007-hash-object.sh
index 285871c24d88c4667d547e957da682fd78bf6ab9..acca9ac562615ddf5c5fabaaa6966f7acc35f95d 100755 (executable)
@@ -101,7 +101,7 @@ test_expect_success 'git hash-object --stdin file1 <file0 first operates on file
        test "$obname1" = "$obname1new"
 '
 
-test_expect_success 'check that appropriate filter is invoke when --path is used' '
+test_expect_success 'set up crlf tests' '
        echo fooQ | tr Q "\\015" >file0 &&
        cp file0 file1 &&
        echo "file0 -crlf" >.gitattributes &&
@@ -109,7 +109,10 @@ test_expect_success 'check that appropriate filter is invoke when --path is used
        git config core.autocrlf true &&
        file0_sha=$(git hash-object file0) &&
        file1_sha=$(git hash-object file1) &&
-       test "$file0_sha" != "$file1_sha" &&
+       test "$file0_sha" != "$file1_sha"
+'
+
+test_expect_success 'check that appropriate filter is invoke when --path is used' '
        path1_sha=$(git hash-object --path=file1 file0) &&
        path0_sha=$(git hash-object --path=file0 file1) &&
        test "$file0_sha" = "$path0_sha" &&
@@ -117,8 +120,7 @@ test_expect_success 'check that appropriate filter is invoke when --path is used
        path1_sha=$(cat file0 | git hash-object --path=file1 --stdin) &&
        path0_sha=$(cat file1 | git hash-object --path=file0 --stdin) &&
        test "$file0_sha" = "$path0_sha" &&
-       test "$file1_sha" = "$path1_sha" &&
-       git config --unset core.autocrlf
+       test "$file1_sha" = "$path1_sha"
 '
 
 test_expect_success 'gitattributes also work in a subdirectory' '
@@ -133,33 +135,15 @@ test_expect_success 'gitattributes also work in a subdirectory' '
 '
 
 test_expect_success 'check that --no-filters option works' '
-       echo fooQ | tr Q "\\015" >file0 &&
-       cp file0 file1 &&
-       echo "file0 -crlf" >.gitattributes &&
-       echo "file1 crlf" >>.gitattributes &&
-       git config core.autocrlf true &&
-       file0_sha=$(git hash-object file0) &&
-       file1_sha=$(git hash-object file1) &&
-       test "$file0_sha" != "$file1_sha" &&
        nofilters_file1=$(git hash-object --no-filters file1) &&
        test "$file0_sha" = "$nofilters_file1" &&
        nofilters_file1=$(cat file1 | git hash-object --stdin) &&
-       test "$file0_sha" = "$nofilters_file1" &&
-       git config --unset core.autocrlf
+       test "$file0_sha" = "$nofilters_file1"
 '
 
 test_expect_success 'check that --no-filters option works with --stdin-paths' '
-       echo fooQ | tr Q "\\015" >file0 &&
-       cp file0 file1 &&
-       echo "file0 -crlf" >.gitattributes &&
-       echo "file1 crlf" >>.gitattributes &&
-       git config core.autocrlf true &&
-       file0_sha=$(git hash-object file0) &&
-       file1_sha=$(git hash-object file1) &&
-       test "$file0_sha" != "$file1_sha" &&
        nofilters_file1=$(echo "file1" | git hash-object --stdin-paths --no-filters) &&
-       test "$file0_sha" = "$nofilters_file1" &&
-       git config --unset core.autocrlf
+       test "$file0_sha" = "$nofilters_file1"
 '
 
 pop_repo