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
7 TEST_PASSES_SANITIZE_LEAK
=true
10 test_expect_success
'setup repo' '
11 test_commit initial &&
12 for i in $(test_seq 1 3)
15 for j in $(test_seq 1 3)
18 echo $j >f$i/f$j/data.txt || return 1
22 git commit -m "Initialized trees" &&
23 for i in $(test_seq 1 3)
25 git checkout -b topic$i main &&
26 echo change-$i >f$i/f$i/data.txt &&
27 git commit -a -m "Changed f$i/f$i/data.txt" || return 1
29 cat >packinput.txt <<-EOF &&
39 topic1:f1/f1/data.txt | sort >expect_objects.txt
42 test_expect_success
'non-sparse pack-objects' '
43 git pack-objects --stdout --revs --no-sparse <packinput.txt >nonsparse.pack &&
44 git index-pack -o nonsparse.idx nonsparse.pack &&
45 git show-index <nonsparse.idx | awk "{print \$2}" >nonsparse_objects.txt &&
46 test_cmp expect_objects.txt nonsparse_objects.txt
49 test_expect_success
'sparse pack-objects' '
50 git pack-objects --stdout --revs --sparse <packinput.txt >sparse.pack &&
51 git index-pack -o sparse.idx sparse.pack &&
52 git show-index <sparse.idx | awk "{print \$2}" >sparse_objects.txt &&
53 test_cmp expect_objects.txt sparse_objects.txt
56 test_expect_success
'duplicate a folder from f3 and commit to topic1' '
57 git checkout topic1 &&
58 echo change-3 >f3/f3/data.txt &&
59 git commit -a -m "Changed f3/f3/data.txt" &&
67 topic1:f1/f1/data.txt | sort >required_objects.txt
70 test_expect_success
'non-sparse pack-objects' '
71 git pack-objects --stdout --revs --no-sparse <packinput.txt >nonsparse.pack &&
72 git index-pack -o nonsparse.idx nonsparse.pack &&
73 git show-index <nonsparse.idx | awk "{print \$2}" >nonsparse_objects.txt &&
74 comm -1 -2 required_objects.txt nonsparse_objects.txt >nonsparse_required_objects.txt &&
75 test_cmp required_objects.txt nonsparse_required_objects.txt
78 test_expect_success
'sparse pack-objects' '
79 git pack-objects --stdout --revs --sparse <packinput.txt >sparse.pack &&
80 git index-pack -o sparse.idx sparse.pack &&
81 git show-index <sparse.idx | awk "{print \$2}" >sparse_objects.txt &&
82 comm -1 -2 required_objects.txt sparse_objects.txt >sparse_required_objects.txt &&
83 test_cmp required_objects.txt sparse_required_objects.txt
86 # Demonstrate that the algorithms differ when we copy a tree wholesale
87 # from one folder to another.
89 test_expect_success
'duplicate a folder from f1 into f3' '
91 cp -r f1/f1/* f3/f4 &&
93 git commit -m "Copied f1/f1 to f3/f4" &&
94 cat >packinput.txt <<-EOF &&
101 topic1:f3 | sort >required_objects.txt
104 test_expect_success
'non-sparse pack-objects' '
105 git pack-objects --stdout --revs --no-sparse <packinput.txt >nonsparse.pack &&
106 git index-pack -o nonsparse.idx nonsparse.pack &&
107 git show-index <nonsparse.idx | awk "{print \$2}" >nonsparse_objects.txt &&
108 comm -1 -2 required_objects.txt nonsparse_objects.txt >nonsparse_required_objects.txt &&
109 test_cmp required_objects.txt nonsparse_required_objects.txt
112 # --sparse is enabled by default by pack.useSparse
113 test_expect_success
'sparse pack-objects' '
114 GIT_TEST_PACK_SPARSE=-1 &&
120 topic1:f3/f4/data.txt | sort >expect_sparse_objects.txt &&
121 git pack-objects --stdout --revs <packinput.txt >sparse.pack &&
122 git index-pack -o sparse.idx sparse.pack &&
123 git show-index <sparse.idx | awk "{print \$2}" >sparse_objects.txt &&
124 test_cmp expect_sparse_objects.txt sparse_objects.txt
127 test_expect_success
'pack.useSparse enables algorithm' '
128 git config pack.useSparse true &&
129 git pack-objects --stdout --revs <packinput.txt >sparse.pack &&
130 git index-pack -o sparse.idx sparse.pack &&
131 git show-index <sparse.idx | awk "{print \$2}" >sparse_objects.txt &&
132 test_cmp expect_sparse_objects.txt sparse_objects.txt
135 test_expect_success
'pack.useSparse overridden' '
136 git pack-objects --stdout --revs --no-sparse <packinput.txt >sparse.pack &&
137 git index-pack -o sparse.idx sparse.pack &&
138 git show-index <sparse.idx | awk "{print \$2}" >sparse_objects.txt &&
139 test_cmp required_objects.txt sparse_objects.txt