t1007: factor out repeated setup

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>

Jeff King committed Sep 12, 2016 at 20:23 UTC 4d0efa101bbbc63d8bd1ec0477f027f23b9f573b
1 file changed +8 -24
t/t1007-hash-object.sh
+8 -24
@@ -101,7 +101,7 @@ test_expect_success 'git hash-object --stdin file1 <file0 first operates on file
101 test "$obname1" = "$obname1new"
102 '
103
104 -test_expect_success 'check that appropriate filter is invoke when --path is used' '
104 +test_expect_success 'set up crlf tests' '
105 echo fooQ | tr Q "\\015" >file0 &&
106 cp file0 file1 &&
107 echo "file0 -crlf" >.gitattributes &&
@@ -109,7 +109,10 @@ test_expect_success 'check that appropriate filter is invoke when --path is used
109 git config core.autocrlf true &&
110 file0_sha=$(git hash-object file0) &&
111 file1_sha=$(git hash-object file1) &&
112 - test "$file0_sha" != "$file1_sha" &&
112 + test "$file0_sha" != "$file1_sha"
113 +'
114 +
115 +test_expect_success 'check that appropriate filter is invoke when --path is used' '
116 path1_sha=$(git hash-object --path=file1 file0) &&
117 path0_sha=$(git hash-object --path=file0 file1) &&
118 test "$file0_sha" = "$path0_sha" &&
@@ -117,8 +120,7 @@ test_expect_success 'check that appropriate filter is invoke when --path is used
120 path1_sha=$(cat file0 | git hash-object --path=file1 --stdin) &&
121 path0_sha=$(cat file1 | git hash-object --path=file0 --stdin) &&
122 test "$file0_sha" = "$path0_sha" &&
120 - test "$file1_sha" = "$path1_sha" &&
121 - git config --unset core.autocrlf
123 + test "$file1_sha" = "$path1_sha"
124 '
125
126 test_expect_success 'gitattributes also work in a subdirectory' '
@@ -133,33 +135,15 @@ test_expect_success 'gitattributes also work in a subdirectory' '
135 '
136
137 test_expect_success 'check that --no-filters option works' '
136 - echo fooQ | tr Q "\\015" >file0 &&
137 - cp file0 file1 &&
138 - echo "file0 -crlf" >.gitattributes &&
139 - echo "file1 crlf" >>.gitattributes &&
140 - git config core.autocrlf true &&
141 - file0_sha=$(git hash-object file0) &&
142 - file1_sha=$(git hash-object file1) &&
143 - test "$file0_sha" != "$file1_sha" &&
138 nofilters_file1=$(git hash-object --no-filters file1) &&
139 test "$file0_sha" = "$nofilters_file1" &&
140 nofilters_file1=$(cat file1 | git hash-object --stdin) &&
147 - test "$file0_sha" = "$nofilters_file1" &&
148 - git config --unset core.autocrlf
141 + test "$file0_sha" = "$nofilters_file1"
142 '
143
144 test_expect_success 'check that --no-filters option works with --stdin-paths' '
152 - echo fooQ | tr Q "\\015" >file0 &&
153 - cp file0 file1 &&
154 - echo "file0 -crlf" >.gitattributes &&
155 - echo "file1 crlf" >>.gitattributes &&
156 - git config core.autocrlf true &&
157 - file0_sha=$(git hash-object file0) &&
158 - file1_sha=$(git hash-object file1) &&
159 - test "$file0_sha" != "$file1_sha" &&
145 nofilters_file1=$(echo "file1" | git hash-object --stdin-paths --no-filters) &&
161 - test "$file0_sha" = "$nofilters_file1" &&
162 - git config --unset core.autocrlf
146 + test "$file0_sha" = "$nofilters_file1"
147 '
148
149 pop_repo