Skip to content

Commit 4d0efa1

Browse files
peffgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 4543926 commit 4d0efa1

File tree

1 file changed

+8
-24
lines changed

1 file changed

+8
-24
lines changed

t/t1007-hash-object.sh

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -101,24 +101,26 @@ test_expect_success 'git hash-object --stdin file1 <file0 first operates on file
101101
test "$obname1" = "$obname1new"
102102
'
103103

104-
test_expect_success 'check that appropriate filter is invoke when --path is used' '
104+
test_expect_success 'set up crlf tests' '
105105
echo fooQ | tr Q "\\015" >file0 &&
106106
cp file0 file1 &&
107107
echo "file0 -crlf" >.gitattributes &&
108108
echo "file1 crlf" >>.gitattributes &&
109109
git config core.autocrlf true &&
110110
file0_sha=$(git hash-object file0) &&
111111
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' '
113116
path1_sha=$(git hash-object --path=file1 file0) &&
114117
path0_sha=$(git hash-object --path=file0 file1) &&
115118
test "$file0_sha" = "$path0_sha" &&
116119
test "$file1_sha" = "$path1_sha" &&
117120
path1_sha=$(cat file0 | git hash-object --path=file1 --stdin) &&
118121
path0_sha=$(cat file1 | git hash-object --path=file0 --stdin) &&
119122
test "$file0_sha" = "$path0_sha" &&
120-
test "$file1_sha" = "$path1_sha" &&
121-
git config --unset core.autocrlf
123+
test "$file1_sha" = "$path1_sha"
122124
'
123125

124126
test_expect_success 'gitattributes also work in a subdirectory' '
@@ -133,33 +135,15 @@ test_expect_success 'gitattributes also work in a subdirectory' '
133135
'
134136

135137
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" &&
144138
nofilters_file1=$(git hash-object --no-filters file1) &&
145139
test "$file0_sha" = "$nofilters_file1" &&
146140
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"
149142
'
150143

151144
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" &&
160145
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"
163147
'
164148

165149
pop_repo

0 commit comments

Comments
 (0)