From 05d5667fec9650b049f47edd8cca23a43b135365 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Wed, 23 Apr 2008 15:17:46 -0400 Subject: git-cat-file: Add --batch-check option This new option allows multiple objects to be specified on stdin. For each object specified, a line of the following form is printed: SP SP LF If the object does not exist in the repository, a line of the following form is printed: SP missing LF Signed-off-by: Adam Roben Signed-off-by: Junio C Hamano --- t/t1006-cat-file.sh | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) (limited to 't/t1006-cat-file.sh') diff --git a/t/t1006-cat-file.sh b/t/t1006-cat-file.sh index 0f7cc0371..decba0274 100755 --- a/t/t1006-cat-file.sh +++ b/t/t1006-cat-file.sh @@ -67,6 +67,19 @@ run_tests () { 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)" + if test "z$expect" = "z$actual" + then + : happy + else + echo "Oops: expected $expect" + echo "but got $actual" + false + fi + ' } hello_content="Hello World" @@ -118,4 +131,56 @@ 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 +do + test_expect_success "Passing -$opt with --batch-check fails" ' + test_must_fail git cat-file --batch-check -$opt $hello_sha1 + ' + + test_expect_success "Passing --batch-check with -$opt fails" ' + test_must_fail git cat-file -$opt --batch-check $hello_sha1 + ' +done + +test_expect_success "Passing with --batch-check fails" ' + test_must_fail git cat-file --batch-check blob $hello_sha1 +' + +test_expect_success "Passing --batch-check with 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 "--batch-check for a non-existent object" ' + test "deadbeef missing" = \ + "$(echo_without_newline deadbeef | git cat-file --batch-check)" +' + +test_expect_success "--batch-check for an emtpy line" ' + test " missing" = "$(echo | git cat-file --batch-check)" +' + +batch_check_input="$hello_sha1 +$tree_sha1 +$commit_sha1 +$tag_sha1 +deadbeef + +" + +batch_check_output="$hello_sha1 blob $hello_size +$tree_sha1 tree $tree_size +$commit_sha1 commit $commit_size +$tag_sha1 tag $tag_size +deadbeef missing + missing" + +test_expect_success "--batch-check with multiple sha1s gives correct format" ' + test "$batch_check_output" = \ + "$(echo_without_newline "$batch_check_input" | git cat-file --batch-check)" +' + test_done -- cgit v1.2.1