]>
Commit | Line | Data |
---|---|---|
919a3c98 CC |
1 | #!/bin/sh |
2 | # | |
3 | # Copyright (c) 2005 Amos Waterland | |
4 | # Copyright (c) 2006 Christian Couder | |
5 | # | |
6 | ||
7 | test_description='git pack-refs should not change the branch semantic | |
8 | ||
9 | This test runs git pack-refs and git show-ref and checks that the branch | |
10 | semantic is still the same. | |
11 | ' | |
12 | . ./test-lib.sh | |
13 | ||
3b463c3f JH |
14 | echo '[core] logallrefupdates = true' >>.git/config |
15 | ||
919a3c98 CC |
16 | test_expect_success \ |
17 | 'prepare a trivial repository' \ | |
18 | 'echo Hello > A && | |
5be60078 | 19 | git update-index --add A && |
0cb0e143 | 20 | git commit -m "Initial commit." && |
5be60078 | 21 | HEAD=$(git rev-parse --verify HEAD)' |
919a3c98 CC |
22 | |
23 | SHA1= | |
24 | ||
25 | test_expect_success \ | |
26 | 'see if git show-ref works as expected' \ | |
5be60078 | 27 | 'git branch a && |
26e5fc34 | 28 | SHA1=`cat .git/refs/heads/a` && |
919a3c98 | 29 | echo "$SHA1 refs/heads/a" >expect && |
5be60078 | 30 | git show-ref a >result && |
4fdf71be | 31 | test_cmp expect result' |
919a3c98 CC |
32 | |
33 | test_expect_success \ | |
34 | 'see if a branch still exists when packed' \ | |
5be60078 JH |
35 | 'git branch b && |
36 | git pack-refs --all && | |
0f018bab | 37 | rm -f .git/refs/heads/b && |
919a3c98 | 38 | echo "$SHA1 refs/heads/b" >expect && |
5be60078 | 39 | git show-ref b >result && |
4fdf71be | 40 | test_cmp expect result' |
919a3c98 | 41 | |
41ac414e JH |
42 | test_expect_success 'git branch c/d should barf if branch c exists' ' |
43 | git branch c && | |
5be60078 | 44 | git pack-refs --all && |
41ac414e | 45 | rm -f .git/refs/heads/c && |
d492b31c | 46 | test_must_fail git branch c/d |
41ac414e | 47 | ' |
919a3c98 CC |
48 | |
49 | test_expect_success \ | |
50 | 'see if a branch still exists after git pack-refs --prune' \ | |
5be60078 JH |
51 | 'git branch e && |
52 | git pack-refs --all --prune && | |
919a3c98 | 53 | echo "$SHA1 refs/heads/e" >expect && |
5be60078 | 54 | git show-ref e >result && |
4fdf71be | 55 | test_cmp expect result' |
919a3c98 | 56 | |
41ac414e JH |
57 | test_expect_success 'see if git pack-refs --prune remove ref files' ' |
58 | git branch f && | |
5be60078 | 59 | git pack-refs --all --prune && |
41ac414e JH |
60 | ! test -f .git/refs/heads/f |
61 | ' | |
919a3c98 | 62 | |
be7c6d46 GP |
63 | test_expect_success 'see if git pack-refs --prune removes empty dirs' ' |
64 | git branch r/s/t && | |
65 | git pack-refs --all --prune && | |
66 | ! test -e .git/refs/heads/r | |
67 | ' | |
68 | ||
919a3c98 CC |
69 | test_expect_success \ |
70 | 'git branch g should work when git branch g/h has been deleted' \ | |
5be60078 JH |
71 | 'git branch g/h && |
72 | git pack-refs --all --prune && | |
73 | git branch -d g/h && | |
74 | git branch g && | |
75 | git pack-refs --all && | |
76 | git branch -d g' | |
919a3c98 | 77 | |
41ac414e JH |
78 | test_expect_success 'git branch i/j/k should barf if branch i exists' ' |
79 | git branch i && | |
5be60078 | 80 | git pack-refs --all --prune && |
d492b31c | 81 | test_must_fail git branch i/j/k |
41ac414e | 82 | ' |
14c8a681 CC |
83 | |
84 | test_expect_success \ | |
85 | 'test git branch k after branch k/l/m and k/lm have been deleted' \ | |
5be60078 JH |
86 | 'git branch k/l && |
87 | git branch k/lm && | |
88 | git branch -d k/l && | |
89 | git branch k/l/m && | |
90 | git branch -d k/l/m && | |
91 | git branch -d k/lm && | |
92 | git branch k' | |
14c8a681 CC |
93 | |
94 | test_expect_success \ | |
95 | 'test git branch n after some branch deletion and pruning' \ | |
5be60078 JH |
96 | 'git branch n/o && |
97 | git branch n/op && | |
98 | git branch -d n/o && | |
99 | git branch n/o/p && | |
100 | git branch -d n/op && | |
101 | git pack-refs --all --prune && | |
102 | git branch -d n/o/p && | |
103 | git branch n' | |
14c8a681 | 104 | |
5bdd8d4a CB |
105 | test_expect_success \ |
106 | 'see if up-to-date packed refs are preserved' \ | |
107 | 'git branch q && | |
108 | git pack-refs --all --prune && | |
109 | git update-ref refs/heads/q refs/heads/q && | |
110 | ! test -f .git/refs/heads/q' | |
111 | ||
1b555932 | 112 | test_expect_success 'pack, prune and repack' ' |
0cb0e143 | 113 | git tag foo && |
5be60078 JH |
114 | git pack-refs --all --prune && |
115 | git show-ref >all-of-them && | |
116 | git pack-refs && | |
117 | git show-ref >again && | |
4fdf71be | 118 | test_cmp all-of-them again |
1b555932 LT |
119 | ' |
120 | ||
0a0b8d15 MH |
121 | test_expect_success 'explicit pack-refs with dangling packed reference' ' |
122 | git commit --allow-empty -m "soon to be garbage-collected" && | |
123 | git pack-refs --all && | |
124 | git reset --hard HEAD^ && | |
125 | git reflog expire --expire=all --all && | |
126 | git prune --expire=all && | |
127 | git pack-refs --all 2>result && | |
128 | test_cmp /dev/null result | |
129 | ' | |
130 | ||
131 | test_expect_success 'delete ref with dangling packed version' ' | |
132 | git checkout -b lamb && | |
133 | git commit --allow-empty -m "future garbage" && | |
134 | git pack-refs --all && | |
135 | git reset --hard HEAD^ && | |
136 | git checkout master && | |
137 | git reflog expire --expire=all --all && | |
138 | git prune --expire=all && | |
139 | git branch -d lamb 2>result && | |
140 | test_cmp /dev/null result | |
141 | ' | |
142 | ||
ab292bc4 | 143 | test_expect_success 'delete ref while another dangling packed ref' ' |
0a0b8d15 MH |
144 | git branch lamb && |
145 | git commit --allow-empty -m "future garbage" && | |
146 | git pack-refs --all && | |
147 | git reset --hard HEAD^ && | |
148 | git reflog expire --expire=all --all && | |
149 | git prune --expire=all && | |
150 | git branch -d lamb 2>result && | |
151 | test_cmp /dev/null result | |
152 | ' | |
153 | ||
919a3c98 | 154 | test_done |