aboutsummaryrefslogtreecommitdiff
path: root/t
diff options
context:
space:
mode:
authorAdam Roben <aroben@apple.com>2008-04-23 15:17:47 -0400
committerJunio C Hamano <gitster@pobox.com>2008-05-05 21:18:37 -0700
commita8128ed62858063e29edc066b14b8b0fa6257cc2 (patch)
tree2315d1b87c16f1d9134e2d2da6a6865f036af8cc /t
parent05d5667fec9650b049f47edd8cca23a43b135365 (diff)
downloadgit-a8128ed62858063e29edc066b14b8b0fa6257cc2.tar.gz
git-a8128ed62858063e29edc066b14b8b0fa6257cc2.tar.xz
git-cat-file: Add --batch option
--batch is similar to --batch-check, except that the contents of each object is also printed. The output's form is: <sha1> SP <type> SP <size> LF <contents> LF Signed-off-by: Adam Roben <aroben@apple.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 't')
-rwxr-xr-xt/t1006-cat-file.sh74
1 files changed, 57 insertions, 17 deletions
diff --git a/t/t1006-cat-file.sh b/t/t1006-cat-file.sh
index decba0274..d5696765b 100755
--- a/t/t1006-cat-file.sh
+++ b/t/t1006-cat-file.sh
@@ -28,6 +28,9 @@ run_tests () {
pretty_content=$5
no_ts=$6
+ batch_output="$sha1 $type $size
+$content"
+
test_expect_success "$type exists" '
git cat-file -e $sha1
'
@@ -68,6 +71,20 @@ run_tests () {
fi
'
+ test -z "$content" ||
+ test_expect_success "--batch output of $type is correct" '
+ expect="$(maybe_remove_timestamp "$batch_output" $no_ts)"
+ actual="$(maybe_remove_timestamp "$(echo $sha1 | git cat-file --batch)" no_ts)"
+ if test "z$expect" = "z$actual"
+ then
+ : happy
+ else
+ echo "Oops: expected $expect"
+ echo "but got $actual"
+ false
+ fi
+ '
+
test_expect_success "--batch-check output of $type is correct" '
expect="$sha1 $type $size"
actual="$(echo_without_newline $sha1 | git cat-file --batch-check)"
@@ -131,28 +148,31 @@ test_expect_success \
"Reach a blob from a tag pointing to it" \
"test '$hello_content' = \"\$(git cat-file blob $tag_sha1)\""
-for opt in t s e p
+for batch in batch batch-check
do
- test_expect_success "Passing -$opt with --batch-check fails" '
- test_must_fail git cat-file --batch-check -$opt $hello_sha1
+ for opt in t s e p
+ do
+ test_expect_success "Passing -$opt with --$batch fails" '
+ test_must_fail git cat-file --$batch -$opt $hello_sha1
+ '
+
+ test_expect_success "Passing --$batch with -$opt fails" '
+ test_must_fail git cat-file -$opt --$batch $hello_sha1
+ '
+ done
+
+ test_expect_success "Passing <type> with --$batch fails" '
+ test_must_fail git cat-file --$batch blob $hello_sha1
'
- test_expect_success "Passing --batch-check with -$opt fails" '
- test_must_fail git cat-file -$opt --batch-check $hello_sha1
+ test_expect_success "Passing --$batch with <type> fails" '
+ test_must_fail git cat-file blob --$batch $hello_sha1
'
-done
-
-test_expect_success "Passing <type> with --batch-check fails" '
- test_must_fail git cat-file --batch-check blob $hello_sha1
-'
-
-test_expect_success "Passing --batch-check with <type> fails" '
- test_must_fail git cat-file blob --batch-check $hello_sha1
-'
-test_expect_success "Passing sha1 with --batch-check fails" '
- test_must_fail git cat-file --batch-check $hello_sha1
-'
+ test_expect_success "Passing sha1 with --$batch fails" '
+ test_must_fail git cat-file --$batch $hello_sha1
+ '
+done
test_expect_success "--batch-check for a non-existent object" '
test "deadbeef missing" = \
@@ -163,6 +183,26 @@ test_expect_success "--batch-check for an emtpy line" '
test " missing" = "$(echo | git cat-file --batch-check)"
'
+batch_input="$hello_sha1
+$commit_sha1
+$tag_sha1
+deadbeef
+
+"
+
+batch_output="$hello_sha1 blob $hello_size
+$hello_content
+$commit_sha1 commit $commit_size
+$commit_content
+$tag_sha1 tag $tag_size
+$tag_content
+deadbeef missing
+ missing"
+
+test_expect_success \
+ "--batch with multiple sha1s gives correct format" \
+ "test \"\$(maybe_remove_timestamp \"$batch_output\" 1)\" = \"\$(maybe_remove_timestamp \"\$(echo_without_newline \"$batch_input\" | git cat-file --batch)\" 1)\""
+
batch_check_input="$hello_sha1
$tree_sha1
$commit_sha1