3 test_description
='git repack works correctly'
11 test_expect_success
'-A with -d option leaves unreachable objects unpacked' '
12 echo content > file1 &&
15 git commit -m initial_commit &&
16 # create a transient branch with unique content
17 git checkout -b transient_branch &&
18 echo more content >> file1 &&
19 # record the objects created in the database for file, commit, tree
20 fsha1=$(git hash-object file1) &&
22 git commit -a -m more_content &&
23 csha1=$(git rev-parse HEAD^{commit}) &&
24 tsha1=$(git rev-parse HEAD^{tree}) &&
25 git checkout master &&
26 echo even more content >> file1 &&
28 git commit -a -m even_more_content &&
29 # delete the transient branch
30 git branch -D transient_branch &&
32 git repack -A -d -l &&
33 # verify objects are packed in repository
34 test 3 = $(git verify-pack -v -- .git/objects/pack/*.idx |
35 egrep "^($fsha1|$csha1|$tsha1) " |
36 sort | uniq | wc -l) &&
40 # now expire the reflog, while keeping reachable ones but expiring
41 # unreachables immediately
43 sometimeago=$(( $test_tick - 10000 )) &&
44 git reflog expire --expire=$sometimeago --expire-unreachable=$test_tick --all &&
46 git repack -A -d -l &&
47 # verify objects are retained unpacked
48 test 0 = $(git verify-pack -v -- .git/objects/pack/*.idx |
49 egrep "^($fsha1|$csha1|$tsha1) " |
50 sort | uniq | wc -l) &&
60 test "$tref" = "$t" ||
return 1
64 test_expect_success
'-A without -d option leaves unreachable objects packed' '
65 fsha1path=$(echo "$fsha1" | sed -e "s|\(..\)|\1/|") &&
66 fsha1path=".git/objects/$fsha1path" &&
67 csha1path=$(echo "$csha1" | sed -e "s|\(..\)|\1/|") &&
68 csha1path=".git/objects/$csha1path" &&
69 tsha1path=$(echo "$tsha1" | sed -e "s|\(..\)|\1/|") &&
70 tsha1path=".git/objects/$tsha1path" &&
71 git branch transient_branch $csha1 &&
72 git repack -a -d -l &&
73 test ! -f "$fsha1path" &&
74 test ! -f "$csha1path" &&
75 test ! -f "$tsha1path" &&
76 test 1 = $(ls -1 .git/objects/pack/pack-*.pack | wc -l) &&
77 packfile=$(ls .git/objects/pack/pack-*.pack) &&
78 git branch -D transient_branch &&
81 test ! -f "$fsha1path" &&
82 test ! -f "$csha1path" &&
83 test ! -f "$tsha1path" &&
89 test_expect_success
'unpacked objects receive timestamp of pack file' '
90 tmppack=".git/objects/pack/tmp_pack" &&
91 ln "$packfile" "$tmppack" &&
92 git repack -A -l -d &&
93 test-tool chmtime --get "$tmppack" "$fsha1path" "$csha1path" "$tsha1path" \
95 compare_mtimes < mtimes
98 test_expect_success
'do not bother loosening old objects' '
99 obj1=$(echo one | git hash-object -w --stdin) &&
100 obj2=$(echo two | git hash-object -w --stdin) &&
101 pack1=$(echo $obj1 | git pack-objects .git/objects/pack/pack) &&
102 pack2=$(echo $obj2 | git pack-objects .git/objects/pack/pack) &&
104 git cat-file -p $obj1 &&
105 git cat-file -p $obj2 &&
106 test-tool chmtime =-86400 .git/objects/pack/pack-$pack2.pack &&
107 git repack -A -d --unpack-unreachable=1.hour.ago &&
108 git cat-file -p $obj1 &&
109 test_must_fail git cat-file -p $obj2
112 test_expect_success
'keep packed objects found only in index' '
113 echo my-unique-content >file &&
115 git commit -m "make it reachable" &&
118 git reflog expire --expire=now --all &&
120 test-tool chmtime =-86400 .git/objects/pack/* &&
121 git gc --prune=1.hour.ago &&
122 git cat-file blob :file
125 test_expect_success
'repack -k keeps unreachable packed objects' '
126 # create packed-but-unreachable object
127 sha1=$(echo unreachable-packed | git hash-object -w --stdin) &&
128 pack=$(echo $sha1 | git pack-objects .git/objects/pack/pack) &&
133 git cat-file -p $sha1 &&
135 # and double check that without -k it would have been removed
137 test_must_fail git cat-file -p $sha1
140 test_expect_success
'repack -k packs unreachable loose objects' '
141 # create loose unreachable object
142 sha1=$(echo would-be-deleted-loose | git hash-object -w --stdin) &&
143 objpath=.git/objects/$(echo $sha1 | sed "s,..,&/,") &&
144 test_path_is_file $objpath &&
146 # and confirm that the loose object goes away, but we can
147 # still access it (ergo, it is packed)
149 test_path_is_missing $objpath &&
150 git cat-file -p $sha1