109
echo_without_newline "$1" | wc -c | sed -e 's/^ *//'
110
}
111
112
-maybe_remove_timestamp () {
113
- if test -z "$2"; then
114
- echo_without_newline "$1"
115
- else
116
- echo_without_newline "$(printf '%s\n' "$1" | remove_timestamp)"
117
- fi
118
-}
119
-
120
-remove_timestamp () {
121
- sed -e 's/ [0-9][0-9]* [-+][0-9][0-9][0-9][0-9]$//'
122
-}
123
-
124
-
112
run_tests () {
113
type=$1
114
sha1=$2
115
size=$3
116
content=$4
117
pretty_content=$5
131
- no_ts=$6
118
119
batch_output="$sha1 $type $size
120
$content"
149
150
test -z "$content" ||
151
test_expect_success "Content of $type is correct" '
166
- maybe_remove_timestamp "$content" $no_ts >expect &&
167
- maybe_remove_timestamp "$(git cat-file $type $sha1)" $no_ts >actual &&
152
+ echo_without_newline "$content" >expect &&
153
+ git cat-file $type $sha1 >actual &&
154
test_cmp expect actual
155
'
156
157
test_expect_success "Pretty content of $type is correct" '
172
- maybe_remove_timestamp "$pretty_content" $no_ts >expect &&
173
- maybe_remove_timestamp "$(git cat-file -p $sha1)" $no_ts >actual &&
158
+ echo_without_newline "$pretty_content" >expect &&
159
+ git cat-file -p $sha1 >actual &&
160
test_cmp expect actual
161
'
162
163
test -z "$content" ||
164
test_expect_success "--batch output of $type is correct" '
179
- maybe_remove_timestamp "$batch_output" $no_ts >expect &&
180
- maybe_remove_timestamp "$(echo $sha1 | git cat-file --batch)" $no_ts >actual &&
165
+ echo "$batch_output" >expect &&
166
+ echo $sha1 | git cat-file --batch >actual &&
167
test_cmp expect actual
168
'
169
177
do
178
test -z "$content" ||
179
test_expect_success "--batch-command $opt output of $type content is correct" '
194
- maybe_remove_timestamp "$batch_output" $no_ts >expect &&
195
- maybe_remove_timestamp "$(test_write_lines "contents $sha1" |
196
- git cat-file --batch-command $opt)" $no_ts >actual &&
180
+ echo "$batch_output" >expect &&
181
+ test_write_lines "contents $sha1" | git cat-file --batch-command $opt >actual &&
182
test_cmp expect actual
183
'
184
213
test_expect_success "--batch without type ($type)" '
214
{
215
echo "$size" &&
231
- maybe_remove_timestamp "$content" $no_ts
216
+ echo "$content"
217
} >expect &&
233
- echo $sha1 | git cat-file --batch="%(objectsize)" >actual.full &&
234
- maybe_remove_timestamp "$(cat actual.full)" $no_ts >actual &&
218
+ echo $sha1 | git cat-file --batch="%(objectsize)" >actual &&
219
test_cmp expect actual
220
'
221
223
test_expect_success "--batch without size ($type)" '
224
{
225
echo "$type" &&
242
- maybe_remove_timestamp "$content" $no_ts
226
+ echo "$content"
227
} >expect &&
244
- echo $sha1 | git cat-file --batch="%(objecttype)" >actual.full &&
245
- maybe_remove_timestamp "$(cat actual.full)" $no_ts >actual &&
228
+ echo $sha1 | git cat-file --batch="%(objecttype)" >actual &&
229
test_cmp expect actual
230
'
231
}
267
268
tree_sha1=$(git write-tree)
269
tree_size=$(($(test_oid rawsz) + 13))
287
-tree_pretty_content="100644 blob $hello_sha1 hello"
270
+tree_pretty_content="100644 blob $hello_sha1 hello${LF}"
271
272
run_tests 'tree' $tree_sha1 $tree_size "" "$tree_pretty_content"
273
275
commit_sha1=$(echo_without_newline "$commit_message" | git commit-tree $tree_sha1)
276
commit_size=$(($(test_oid hexsz) + 137))
277
commit_content="tree $tree_sha1
295
-author $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> 0 +0000
296
-committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 0 +0000
278
+author $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> $GIT_AUTHOR_DATE
279
+committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
280
281
$commit_message"
282
300
-run_tests 'commit' $commit_sha1 $commit_size "$commit_content" "$commit_content" 1
283
+run_tests 'commit' $commit_sha1 $commit_size "$commit_content" "$commit_content"
284
285
tag_header_without_timestamp="object $hello_sha1
286
type blob
294
tag_sha1=$(echo_without_newline "$tag_content" | git hash-object -t tag --stdin -w)
295
tag_size=$(strlen "$tag_content")
296
314
-run_tests 'tag' $tag_sha1 $tag_size "$tag_content" "$tag_content" 1
297
+run_tests 'tag' $tag_sha1 $tag_size "$tag_content" "$tag_content"
298
299
test_expect_success \
300
"Reach a blob from a tag pointing to it" \
383
missing"
384
385
test_expect_success '--batch with multiple sha1s gives correct format' '
403
- test "$(maybe_remove_timestamp "$batch_output" 1)" = "$(maybe_remove_timestamp "$(echo_without_newline "$batch_input" | git cat-file --batch)" 1)"
386
+ echo "$batch_output" >expect &&
387
+ echo_without_newline "$batch_input" | git cat-file --batch >actual &&
388
+ test_cmp expect actual
389
'
390
391
test_expect_success '--batch, -z with multiple sha1s gives correct format' '
392
echo_without_newline_nul "$batch_input" >in &&
408
- test "$(maybe_remove_timestamp "$batch_output" 1)" = \
409
- "$(maybe_remove_timestamp "$(git cat-file --batch -z <in)" 1)"
393
+ echo "$batch_output" >expect &&
394
+ git cat-file --batch -z <in >actual &&
395
+ test_cmp expect actual
396
'
397
398
batch_check_input="$hello_sha1
466
flush"
467
468
test_expect_success '--batch-command with multiple command calls gives correct format' '
483
- remove_timestamp >expect <<-EOF &&
469
+ cat >expect <<-EOF &&
470
$hello_sha1 blob $hello_size
471
$hello_content
472
$commit_sha1 commit $commit_size
477
EOF
478
479
echo "$batch_command_multiple_contents" >in &&
494
- git cat-file --batch-command --buffer <in >actual_raw &&
480
+ git cat-file --batch-command --buffer <in >actual &&
481
496
- remove_timestamp <actual_raw >actual &&
482
test_cmp expect actual &&
483
484
echo "$batch_command_multiple_contents" | tr "\n" "\0" >in &&
500
- git cat-file --batch-command --buffer -z <in >actual_raw &&
485
+ git cat-file --batch-command --buffer -z <in >actual &&
486
502
- remove_timestamp <actual_raw >actual &&
487
test_cmp expect actual
488
'
489