3 test_description='pack-objects object selection using sparse algorithm'
6 test_expect_success 'setup repo' '
8 for i in $(test_seq 1 3)
11 for j in $(test_seq 1 3)
14 echo $j >f$i/f$j/data.txt
18 git commit -m "Initialized trees" &&
19 for i in $(test_seq 1 3)
21 git checkout -b topic$i master &&
22 echo change-$i >f$i/f$i/data.txt &&
23 git commit -a -m "Changed f$i/f$i/data.txt"
25 cat >packinput.txt <<-EOF &&
35 topic1:f1/f1/data.txt | sort >expect_objects.txt
38 test_expect_success 'non-sparse pack-objects' '
39 git pack-objects --stdout --revs --no-sparse <packinput.txt >nonsparse.pack &&
40 git index-pack -o nonsparse.idx nonsparse.pack &&
41 git show-index <nonsparse.idx | awk "{print \$2}" >nonsparse_objects.txt &&
42 test_cmp expect_objects.txt nonsparse_objects.txt
45 test_expect_success 'sparse pack-objects' '
46 git pack-objects --stdout --revs --sparse <packinput.txt >sparse.pack &&
47 git index-pack -o sparse.idx sparse.pack &&
48 git show-index <sparse.idx | awk "{print \$2}" >sparse_objects.txt &&
49 test_cmp expect_objects.txt sparse_objects.txt
52 test_expect_success 'duplicate a folder from f3 and commit to topic1' '
53 git checkout topic1 &&
54 echo change-3 >f3/f3/data.txt &&
55 git commit -a -m "Changed f3/f3/data.txt" &&
63 topic1:f1/f1/data.txt | sort >required_objects.txt
66 test_expect_success 'non-sparse pack-objects' '
67 git pack-objects --stdout --revs --no-sparse <packinput.txt >nonsparse.pack &&
68 git index-pack -o nonsparse.idx nonsparse.pack &&
69 git show-index <nonsparse.idx | awk "{print \$2}" >nonsparse_objects.txt &&
70 comm -1 -2 required_objects.txt nonsparse_objects.txt >nonsparse_required_objects.txt &&
71 test_cmp required_objects.txt nonsparse_required_objects.txt
74 test_expect_success 'sparse pack-objects' '
75 git pack-objects --stdout --revs --sparse <packinput.txt >sparse.pack &&
76 git index-pack -o sparse.idx sparse.pack &&
77 git show-index <sparse.idx | awk "{print \$2}" >sparse_objects.txt &&
78 comm -1 -2 required_objects.txt sparse_objects.txt >sparse_required_objects.txt &&
79 test_cmp required_objects.txt sparse_required_objects.txt
82 # Demonstrate that the algorithms differ when we copy a tree wholesale
83 # from one folder to another.
85 test_expect_success 'duplicate a folder from f1 into f3' '
87 cp -r f1/f1/* f3/f4 &&
89 git commit -m "Copied f1/f1 to f3/f4" &&
90 cat >packinput.txt <<-EOF &&
97 topic1:f3 | sort >required_objects.txt
100 test_expect_success 'non-sparse pack-objects' '
101 git pack-objects --stdout --revs --no-sparse <packinput.txt >nonsparse.pack &&
102 git index-pack -o nonsparse.idx nonsparse.pack &&
103 git show-index <nonsparse.idx | awk "{print \$2}" >nonsparse_objects.txt &&
104 comm -1 -2 required_objects.txt nonsparse_objects.txt >nonsparse_required_objects.txt &&
105 test_cmp required_objects.txt nonsparse_required_objects.txt
108 # --sparse is enabled by default by pack.useSparse
109 test_expect_success 'sparse pack-objects' '
110 GIT_TEST_PACK_SPARSE=-1 &&
116 topic1:f3/f4/data.txt | sort >expect_sparse_objects.txt &&
117 git pack-objects --stdout --revs <packinput.txt >sparse.pack &&
118 git index-pack -o sparse.idx sparse.pack &&
119 git show-index <sparse.idx | awk "{print \$2}" >sparse_objects.txt &&
120 test_cmp expect_sparse_objects.txt sparse_objects.txt
123 test_expect_success 'pack.useSparse enables algorithm' '
124 git config pack.useSparse true &&
125 git pack-objects --stdout --revs <packinput.txt >sparse.pack &&
126 git index-pack -o sparse.idx sparse.pack &&
127 git show-index <sparse.idx | awk "{print \$2}" >sparse_objects.txt &&
128 test_cmp expect_sparse_objects.txt sparse_objects.txt
131 test_expect_success 'pack.useSparse overridden' '
132 git pack-objects --stdout --revs --no-sparse <packinput.txt >sparse.pack &&
133 git index-pack -o sparse.idx sparse.pack &&
134 git show-index <sparse.idx | awk "{print \$2}" >sparse_objects.txt &&
135 test_cmp required_objects.txt sparse_objects.txt