cat-file: provide %(deltabase) batch format
[gitweb.git] / t / t1006-cat-file.sh
index 4e911fb43d8ea2c699b3a836547b618274db6e05..633dc825ec49eb98be10c8f75545a6978c290231 100755 (executable)
@@ -78,6 +78,13 @@ $content"
        echo $sha1 | git cat-file --batch-check="%(objecttype) %(objectname)" >actual &&
        test_cmp expect actual
     '
+
+    test_expect_success '--batch-check with %(rest)' '
+       echo "$type this is some extra content" >expect &&
+       echo "$sha1    this is some extra content" |
+               git cat-file --batch-check="%(objecttype) %(rest)" >actual &&
+       test_cmp expect actual
+    '
 }
 
 hello_content="Hello World"
@@ -91,6 +98,14 @@ test_expect_success "setup" '
 
 run_tests 'blob' $hello_sha1 $hello_size "$hello_content" "$hello_content"
 
+test_expect_success '--batch-check without %(rest) considers whole line' '
+       echo "$hello_sha1 blob $hello_size" >expect &&
+       git update-index --add --cacheinfo 100644 $hello_sha1 "white space" &&
+       test_when_finished "git update-index --remove \"white space\"" &&
+       echo ":white space" | git cat-file --batch-check >actual &&
+       test_cmp expect actual
+'
+
 tree_sha1=$(git write-tree)
 tree_size=33
 tree_pretty_content="100644 blob $hello_sha1   hello"
@@ -179,6 +194,12 @@ test_expect_success "--batch-check for an emtpy line" '
     test " missing" = "$(echo | git cat-file --batch-check)"
 '
 
+test_expect_success 'empty --batch-check notices missing object' '
+       echo "$_z40 missing" >expect &&
+       echo "$_z40" | git cat-file --batch-check="" >actual &&
+       test_cmp expect actual
+'
+
 batch_input="$hello_sha1
 $commit_sha1
 $tag_sha1
@@ -219,4 +240,38 @@ test_expect_success "--batch-check with multiple sha1s gives correct format" '
     "$(echo_without_newline "$batch_check_input" | git cat-file --batch-check)"
 '
 
+test_expect_success 'setup blobs which are likely to delta' '
+       test-genrandom foo 10240 >foo &&
+       { cat foo; echo plus; } >foo-plus &&
+       git add foo foo-plus &&
+       git commit -m foo &&
+       cat >blobs <<-\EOF
+       HEAD:foo
+       HEAD:foo-plus
+       EOF
+'
+
+test_expect_success 'confirm that neither loose blob is a delta' '
+       cat >expect <<-EOF
+       $_z40
+       $_z40
+       EOF
+       git cat-file --batch-check="%(deltabase)" <blobs >actual &&
+       test_cmp expect actual
+'
+
+# To avoid relying too much on the current delta heuristics,
+# we will check only that one of the two objects is a delta
+# against the other, but not the order. We can do so by just
+# asking for the base of both, and checking whether either
+# sha1 appears in the output.
+test_expect_success '%(deltabase) reports packed delta bases' '
+       git repack -ad &&
+       git cat-file --batch-check="%(deltabase)" <blobs >actual &&
+       {
+               grep "$(git rev-parse HEAD:foo)" actual ||
+               grep "$(git rev-parse HEAD:foo-plus)" actual
+       }
+'
+
 test_done