]>
Commit | Line | Data |
---|---|---|
ccc12972 BC |
1 | #!/bin/sh |
2 | ||
47a528ad | 3 | test_description='git repack works correctly' |
ccc12972 BC |
4 | |
5 | . ./test-lib.sh | |
6 | ||
e896912c BC |
7 | fsha1= |
8 | csha1= | |
9 | tsha1= | |
10 | ||
83d0289d | 11 | test_expect_success '-A with -d option leaves unreachable objects unpacked' ' |
ccc12972 BC |
12 | echo content > file1 && |
13 | git add . && | |
713c79e8 | 14 | test_tick && |
ccc12972 BC |
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) && | |
713c79e8 | 21 | test_tick && |
ccc12972 BC |
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 && | |
713c79e8 | 27 | test_tick && |
ccc12972 BC |
28 | git commit -a -m even_more_content && |
29 | # delete the transient branch | |
30 | git branch -D transient_branch && | |
31 | # pack the repo | |
32 | git repack -A -d -l && | |
33 | # verify objects are packed in repository | |
34 | test 3 = $(git verify-pack -v -- .git/objects/pack/*.idx | | |
87539416 | 35 | egrep "^($fsha1|$csha1|$tsha1) " | |
ccc12972 BC |
36 | sort | uniq | wc -l) && |
37 | git show $fsha1 && | |
38 | git show $csha1 && | |
39 | git show $tsha1 && | |
713c79e8 JH |
40 | # now expire the reflog, while keeping reachable ones but expiring |
41 | # unreachables immediately | |
42 | test_tick && | |
43 | sometimeago=$(( $test_tick - 10000 )) && | |
44 | git reflog expire --expire=$sometimeago --expire-unreachable=$test_tick --all && | |
ccc12972 BC |
45 | # and repack |
46 | git repack -A -d -l && | |
47 | # verify objects are retained unpacked | |
48 | test 0 = $(git verify-pack -v -- .git/objects/pack/*.idx | | |
87539416 | 49 | egrep "^($fsha1|$csha1|$tsha1) " | |
ccc12972 BC |
50 | sort | uniq | wc -l) && |
51 | git show $fsha1 && | |
52 | git show $csha1 && | |
53 | git show $tsha1 | |
54 | ' | |
55 | ||
e896912c BC |
56 | compare_mtimes () |
57 | { | |
d0409938 JS |
58 | read tref rest && |
59 | while read t rest; do | |
60 | test "$tref" = "$t" || break | |
61 | done | |
e896912c BC |
62 | } |
63 | ||
83d0289d | 64 | test_expect_success '-A without -d option leaves unreachable objects packed' ' |
e896912c BC |
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 && | |
713c79e8 | 79 | test_tick && |
e896912c | 80 | git repack -A -l && |
83d0289d BC |
81 | test ! -f "$fsha1path" && |
82 | test ! -f "$csha1path" && | |
83 | test ! -f "$tsha1path" && | |
84 | git show $fsha1 && | |
85 | git show $csha1 && | |
86 | git show $tsha1 | |
87 | ' | |
88 | ||
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 && | |
d0409938 JS |
93 | test-chmtime -v +0 "$tmppack" "$fsha1path" "$csha1path" "$tsha1path" \ |
94 | > mtimes && | |
95 | compare_mtimes < mtimes | |
e896912c BC |
96 | ' |
97 | ||
ccc12972 | 98 | test_done |