Merge branch 'md/filter-trees'
[gitweb.git] / t / t5317-pack-objects-filter-objects.sh
index 2e718f0bdede397d399399536707743f9f7cff34..24541ea137517354a8b738bdef34728b49f2850e 100755 (executable)
@@ -67,6 +67,47 @@ test_expect_success 'verify normal and blob:none packfiles have same commits/tre
        test_cmp expected observed
 '
 
+test_expect_success 'get an error for missing tree object' '
+       git init r5 &&
+       echo foo >r5/foo &&
+       git -C r5 add foo &&
+       git -C r5 commit -m "foo" &&
+       del=$(git -C r5 rev-parse HEAD^{tree} | sed "s|..|&/|") &&
+       rm r5/.git/objects/$del &&
+       test_must_fail git -C r5 pack-objects --rev --stdout 2>bad_tree <<-EOF &&
+       HEAD
+       EOF
+       grep "bad tree object" bad_tree
+'
+
+test_expect_success 'setup for tests of tree:0' '
+       mkdir r1/subtree &&
+       echo "This is a file in a subtree" >r1/subtree/file &&
+       git -C r1 add subtree/file &&
+       git -C r1 commit -m subtree
+'
+
+test_expect_success 'verify tree:0 packfile has no blobs or trees' '
+       git -C r1 pack-objects --rev --stdout --filter=tree:0 >commitsonly.pack <<-EOF &&
+       HEAD
+       EOF
+       git -C r1 index-pack ../commitsonly.pack &&
+       git -C r1 verify-pack -v ../commitsonly.pack >objs &&
+       ! grep -E "tree|blob" objs
+'
+
+test_expect_success 'grab tree directly when using tree:0' '
+       # We should get the tree specified directly but not its blobs or subtrees.
+       git -C r1 pack-objects --rev --stdout --filter=tree:0 >commitsonly.pack <<-EOF &&
+       HEAD:
+       EOF
+       git -C r1 index-pack ../commitsonly.pack &&
+       git -C r1 verify-pack -v ../commitsonly.pack >objs &&
+       awk "/tree|blob/{print \$1}" objs >trees_and_blobs &&
+       git -C r1 rev-parse HEAD: >expected &&
+       test_cmp expected trees_and_blobs
+'
+
 # Test blob:limit=<n>[kmg] filter.
 # We boundary test around the size parameter.  The filter is strictly less than
 # the value, so size 500 and 1000 should have the same results, but 1001 should