3 test_description='pack-objects object selection using sparse algorithm'
4 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
5 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
9 test_expect_success 'setup repo' '
10 test_commit initial &&
11 for i in $(test_seq 1 3)
14 for j in $(test_seq 1 3)
17 echo $j >f$i/f$j/data.txt
21 git commit -m "Initialized trees" &&
22 for i in $(test_seq 1 3)
24 git checkout -b topic$i main &&
25 echo change-$i >f$i/f$i/data.txt &&
26 git commit -a -m "Changed f$i/f$i/data.txt"
28 cat >packinput.txt <<-EOF &&
38 topic1:f1/f1/data.txt | sort >expect_objects.txt
41 test_expect_success 'non-sparse pack-objects' '
42 git pack-objects --stdout --revs --no-sparse <packinput.txt >nonsparse.pack &&
43 git index-pack -o nonsparse.idx nonsparse.pack &&
44 git show-index <nonsparse.idx | awk "{print \$2}" >nonsparse_objects.txt &&
45 test_cmp expect_objects.txt nonsparse_objects.txt
48 test_expect_success 'sparse pack-objects' '
49 git pack-objects --stdout --revs --sparse <packinput.txt >sparse.pack &&
50 git index-pack -o sparse.idx sparse.pack &&
51 git show-index <sparse.idx | awk "{print \$2}" >sparse_objects.txt &&
52 test_cmp expect_objects.txt sparse_objects.txt
55 test_expect_success 'duplicate a folder from f3 and commit to topic1' '
56 git checkout topic1 &&
57 echo change-3 >f3/f3/data.txt &&
58 git commit -a -m "Changed f3/f3/data.txt" &&
66 topic1:f1/f1/data.txt | sort >required_objects.txt
69 test_expect_success 'non-sparse pack-objects' '
70 git pack-objects --stdout --revs --no-sparse <packinput.txt >nonsparse.pack &&
71 git index-pack -o nonsparse.idx nonsparse.pack &&
72 git show-index <nonsparse.idx | awk "{print \$2}" >nonsparse_objects.txt &&
73 comm -1 -2 required_objects.txt nonsparse_objects.txt >nonsparse_required_objects.txt &&
74 test_cmp required_objects.txt nonsparse_required_objects.txt
77 test_expect_success 'sparse pack-objects' '
78 git pack-objects --stdout --revs --sparse <packinput.txt >sparse.pack &&
79 git index-pack -o sparse.idx sparse.pack &&
80 git show-index <sparse.idx | awk "{print \$2}" >sparse_objects.txt &&
81 comm -1 -2 required_objects.txt sparse_objects.txt >sparse_required_objects.txt &&
82 test_cmp required_objects.txt sparse_required_objects.txt
85 # Demonstrate that the algorithms differ when we copy a tree wholesale
86 # from one folder to another.
88 test_expect_success 'duplicate a folder from f1 into f3' '
90 cp -r f1/f1/* f3/f4 &&
92 git commit -m "Copied f1/f1 to f3/f4" &&
93 cat >packinput.txt <<-EOF &&
100 topic1:f3 | sort >required_objects.txt
103 test_expect_success 'non-sparse pack-objects' '
104 git pack-objects --stdout --revs --no-sparse <packinput.txt >nonsparse.pack &&
105 git index-pack -o nonsparse.idx nonsparse.pack &&
106 git show-index <nonsparse.idx | awk "{print \$2}" >nonsparse_objects.txt &&
107 comm -1 -2 required_objects.txt nonsparse_objects.txt >nonsparse_required_objects.txt &&
108 test_cmp required_objects.txt nonsparse_required_objects.txt
111 # --sparse is enabled by default by pack.useSparse
112 test_expect_success 'sparse pack-objects' '
113 GIT_TEST_PACK_SPARSE=-1 &&
119 topic1:f3/f4/data.txt | sort >expect_sparse_objects.txt &&
120 git pack-objects --stdout --revs <packinput.txt >sparse.pack &&
121 git index-pack -o sparse.idx sparse.pack &&
122 git show-index <sparse.idx | awk "{print \$2}" >sparse_objects.txt &&
123 test_cmp expect_sparse_objects.txt sparse_objects.txt
126 test_expect_success 'pack.useSparse enables algorithm' '
127 git config pack.useSparse true &&
128 git pack-objects --stdout --revs <packinput.txt >sparse.pack &&
129 git index-pack -o sparse.idx sparse.pack &&
130 git show-index <sparse.idx | awk "{print \$2}" >sparse_objects.txt &&
131 test_cmp expect_sparse_objects.txt sparse_objects.txt
134 test_expect_success 'pack.useSparse overridden' '
135 git pack-objects --stdout --revs --no-sparse <packinput.txt >sparse.pack &&
136 git index-pack -o sparse.idx sparse.pack &&
137 git show-index <sparse.idx | awk "{print \$2}" >sparse_objects.txt &&
138 test_cmp required_objects.txt sparse_objects.txt