3 test_description
='git cat-file'
7 echo_without_newline
() {
12 echo_without_newline
"$1" |
wc -c |
sed -e 's/^ *//'
15 maybe_remove_timestamp
() {
17 echo_without_newline
"$1"
19 echo_without_newline
"$(printf '%s\n' "$1" | sed -e 's/ [0-9][0-9]* [-+][0-9][0-9][0-9][0-9]$//')"
31 batch_output
="$sha1 $type $size
34 test_expect_success
"$type exists" '
38 test_expect_success
"Type of $type is correct" '
39 test $type = "$(git cat-file -t $sha1)"
42 test_expect_success
"Size of $type is correct" '
43 test $size = "$(git cat-file -s $sha1)"
47 test_expect_success
"Content of $type is correct" '
48 expect="$(maybe_remove_timestamp "$content" $no_ts)"
49 actual="$(maybe_remove_timestamp "$(git cat-file $type $sha1)" $no_ts)"
51 if test "z$expect" = "z$actual"
55 echo "Oops: expected $expect"
56 echo "but got $actual"
61 test_expect_success
"Pretty content of $type is correct" '
62 expect="$(maybe_remove_timestamp "$pretty_content" $no_ts)"
63 actual="$(maybe_remove_timestamp "$(git cat-file -p $sha1)" $no_ts)"
64 if test "z$expect" = "z$actual"
68 echo "Oops: expected $expect"
69 echo "but got $actual"
75 test_expect_success
"--batch output of $type is correct" '
76 expect="$(maybe_remove_timestamp "$batch_output" $no_ts)"
77 actual="$(maybe_remove_timestamp "$(echo $sha1 | git cat-file --batch)" $no_ts)"
78 if test "z$expect" = "z$actual"
82 echo "Oops: expected $expect"
83 echo "but got $actual"
88 test_expect_success
"--batch-check output of $type is correct" '
89 expect="$sha1 $type $size"
90 actual="$(echo_without_newline $sha1 | git cat-file --batch-check)"
91 if test "z$expect" = "z$actual"
95 echo "Oops: expected $expect"
96 echo "but got $actual"
102 hello_content
="Hello World"
103 hello_size
=$
(strlen
"$hello_content")
104 hello_sha1
=$
(echo_without_newline
"$hello_content" | git hash-object
--stdin)
106 test_expect_success
"setup" '
107 echo_without_newline "$hello_content" > hello &&
108 git update-index --add hello
111 run_tests
'blob' $hello_sha1 $hello_size "$hello_content" "$hello_content"
113 tree_sha1
=$
(git write-tree
)
115 tree_pretty_content
="100644 blob $hello_sha1 hello"
117 run_tests
'tree' $tree_sha1 $tree_size "" "$tree_pretty_content"
119 commit_message
="Initial commit"
120 commit_sha1
=$
(echo_without_newline
"$commit_message" | git commit-tree
$tree_sha1)
122 commit_content
="tree $tree_sha1
123 author $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> 0000000000 +0000
124 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 0000000000 +0000
128 run_tests
'commit' $commit_sha1 $commit_size "$commit_content" "$commit_content" 1
130 tag_header_without_timestamp
="object $hello_sha1
133 tagger $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>"
134 tag_description
="This is a tag"
135 tag_content
="$tag_header_without_timestamp 0000000000 +0000
139 tag_sha1
=$
(echo_without_newline
"$tag_content" | git mktag
)
140 tag_size
=$
(strlen
"$tag_content")
142 run_tests
'tag' $tag_sha1 $tag_size "$tag_content" "$tag_content" 1
144 test_expect_success \
145 "Reach a blob from a tag pointing to it" \
146 "test '$hello_content' = \"\$(git cat-file blob $tag_sha1)\""
148 for batch in batch batch-check
152 test_expect_success
"Passing -$opt with --$batch fails" '
153 test_must_fail git cat-file --$batch -$opt $hello_sha1
156 test_expect_success
"Passing --$batch with -$opt fails" '
157 test_must_fail git cat-file -$opt --$batch $hello_sha1
161 test_expect_success
"Passing <type> with --$batch fails" '
162 test_must_fail git cat-file --$batch blob $hello_sha1
165 test_expect_success
"Passing --$batch with <type> fails" '
166 test_must_fail git cat-file blob --$batch $hello_sha1
169 test_expect_success
"Passing sha1 with --$batch fails" '
170 test_must_fail git cat-file --$batch $hello_sha1
174 test_expect_success
"--batch-check for a non-existent named object" '
175 test "foobar42 missing
176 foobar84 missing" = \
177 "$( ( echo foobar42; echo_without_newline foobar84; ) | git cat-file --batch-check)"
180 test_expect_success
"--batch-check for a non-existent hash" '
181 test "0000000000000000000000000000000000000042 missing
182 0000000000000000000000000000000000000084 missing" = \
183 "$( ( echo 0000000000000000000000000000000000000042;
184 echo_without_newline 0000000000000000000000000000000000000084; ) \
185 | git cat-file --batch-check)"
188 test_expect_success
"--batch for an existent and a non-existent hash" '
189 test "$tag_sha1 tag $tag_size
191 0000000000000000000000000000000000000000 missing" = \
192 "$( ( echo $tag_sha1;
193 echo_without_newline 0000000000000000000000000000000000000000; ) \
194 | git cat-file --batch)"
197 test_expect_success
"--batch-check for an emtpy line" '
198 test " missing" = "$(echo | git cat-file --batch-check)"
201 batch_input
="$hello_sha1
208 batch_output
="$hello_sha1 blob $hello_size
210 $commit_sha1 commit $commit_size
212 $tag_sha1 tag $tag_size
217 test_expect_success
'--batch with multiple sha1s gives correct format' '
218 test "$(maybe_remove_timestamp "$batch_output" 1)" = "$(maybe_remove_timestamp "$(echo_without_newline "$batch_input" | git cat-file --batch)" 1)"
221 batch_check_input
="$hello_sha1
229 batch_check_output
="$hello_sha1 blob $hello_size
230 $tree_sha1 tree $tree_size
231 $commit_sha1 commit $commit_size
232 $tag_sha1 tag $tag_size
236 test_expect_success
"--batch-check with multiple sha1s gives correct format" '
237 test "$batch_check_output" = \
238 "$(echo_without_newline "$batch_check_input" | git cat-file --batch-check)"