]>
Commit | Line | Data |
---|---|---|
d3038d22 JK |
1 | #!/bin/sh |
2 | # | |
3 | # This test covers the handling of objects which might have old | |
4 | # mtimes in the filesystem (because they were used previously) | |
5 | # and are just now becoming referenced again. | |
6 | # | |
7 | # We're going to do two things that are a little bit "fake" to | |
8 | # help make our simulation easier: | |
9 | # | |
10 | # 1. We'll turn off reflogs. You can still run into | |
11 | # problems with reflogs on, but your objects | |
12 | # don't get pruned until both the reflog expiration | |
13 | # has passed on their references, _and_ they are out | |
14 | # of prune's expiration period. Dropping reflogs | |
15 | # means we only have to deal with one variable in our tests, | |
16 | # but the results generalize. | |
17 | # | |
18 | # 2. We'll use a temporary index file to create our | |
19 | # works-in-progress. Most workflows would mention | |
20 | # referenced objects in the index, which prune takes | |
21 | # into account. However, many operations don't. For | |
22 | # example, a partial commit with "git commit foo" | |
23 | # will use a temporary index. Or they may not need | |
24 | # an index at all (e.g., creating a new commit | |
25 | # to refer to an existing tree). | |
26 | ||
27 | test_description='check pruning of dependent objects' | |
5902f5f4 | 28 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main |
334afbc7 JS |
29 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME |
30 | ||
d3038d22 JK |
31 | . ./test-lib.sh |
32 | ||
33 | # We care about reachability, so we do not want to use | |
34 | # the normal test_commit, which creates extra tags. | |
35 | add () { | |
36 | echo "$1" >"$1" && | |
37 | git add "$1" | |
38 | } | |
39 | commit () { | |
40 | test_tick && | |
41 | add "$1" && | |
42 | git commit -m "$1" | |
43 | } | |
44 | ||
abcb8655 JK |
45 | maybe_repack () { |
46 | if test -n "$repack"; then | |
47 | git repack -ad | |
48 | fi | |
49 | } | |
50 | ||
51 | for repack in '' true; do | |
52 | title=${repack:+repack} | |
53 | title=${title:-loose} | |
54 | ||
55 | test_expect_success "make repo completely empty ($title)" ' | |
56 | rm -rf .git && | |
57 | git init | |
58 | ' | |
59 | ||
60 | test_expect_success "disable reflogs ($title)" ' | |
61 | git config core.logallrefupdates false && | |
d0ab0584 | 62 | git reflog expire --expire=all --all |
abcb8655 | 63 | ' |
d3038d22 | 64 | |
abcb8655 JK |
65 | test_expect_success "setup basic history ($title)" ' |
66 | commit base | |
67 | ' | |
d3038d22 | 68 | |
abcb8655 JK |
69 | test_expect_success "create and abandon some objects ($title)" ' |
70 | git checkout -b experiment && | |
71 | commit abandon && | |
72 | maybe_repack && | |
5902f5f4 | 73 | git checkout main && |
abcb8655 JK |
74 | git branch -D experiment |
75 | ' | |
d3038d22 | 76 | |
abcb8655 | 77 | test_expect_success "simulate time passing ($title)" ' |
deb9845a | 78 | test-tool chmtime --get -86400 $(find .git/objects -type f) |
abcb8655 | 79 | ' |
d3038d22 | 80 | |
abcb8655 JK |
81 | test_expect_success "start writing new commit with old blob ($title)" ' |
82 | tree=$( | |
83 | GIT_INDEX_FILE=index.tmp && | |
84 | export GIT_INDEX_FILE && | |
85 | git read-tree HEAD && | |
86 | add unrelated && | |
87 | add abandon && | |
88 | git write-tree | |
89 | ) | |
90 | ' | |
d3038d22 | 91 | |
abcb8655 JK |
92 | test_expect_success "simultaneous gc ($title)" ' |
93 | git gc --prune=12.hours.ago | |
94 | ' | |
d3038d22 | 95 | |
abcb8655 JK |
96 | test_expect_success "finish writing out commit ($title)" ' |
97 | commit=$(echo foo | git commit-tree -p HEAD $tree) && | |
98 | git update-ref HEAD $commit | |
99 | ' | |
d3038d22 | 100 | |
abcb8655 JK |
101 | # "abandon" blob should have been rescued by reference from new tree |
102 | test_expect_success "repository passes fsck ($title)" ' | |
103 | git fsck | |
104 | ' | |
33d4221c JK |
105 | |
106 | test_expect_success "abandon objects again ($title)" ' | |
107 | git reset --hard HEAD^ && | |
deb9845a | 108 | test-tool chmtime --get -86400 $(find .git/objects -type f) |
33d4221c JK |
109 | ' |
110 | ||
111 | test_expect_success "start writing new commit with same tree ($title)" ' | |
112 | tree=$( | |
113 | GIT_INDEX_FILE=index.tmp && | |
114 | export GIT_INDEX_FILE && | |
115 | git read-tree HEAD && | |
116 | add abandon && | |
117 | add unrelated && | |
118 | git write-tree | |
119 | ) | |
120 | ' | |
121 | ||
122 | test_expect_success "simultaneous gc ($title)" ' | |
123 | git gc --prune=12.hours.ago | |
124 | ' | |
125 | ||
126 | # tree should have been refreshed by write-tree | |
127 | test_expect_success "finish writing out commit ($title)" ' | |
128 | commit=$(echo foo | git commit-tree -p HEAD $tree) && | |
129 | git update-ref HEAD $commit | |
130 | ' | |
abcb8655 | 131 | done |
d3038d22 | 132 | |
a3ba6bf1 | 133 | test_expect_success 'do not complain about existing broken links (commit)' ' |
252a4ee6 | 134 | cat >broken-commit <<-EOF && |
135 | tree $(test_oid 001) | |
136 | parent $(test_oid 002) | |
daf7d867 JK |
137 | author whatever <whatever@example.com> 1234 -0000 |
138 | committer whatever <whatever@example.com> 1234 -0000 | |
139 | ||
140 | some message | |
141 | EOF | |
142 | commit=$(git hash-object -t commit -w broken-commit) && | |
b068d9a2 | 143 | git gc -q 2>stderr && |
daf7d867 JK |
144 | verbose git cat-file -e $commit && |
145 | test_must_be_empty stderr | |
146 | ' | |
147 | ||
a3ba6bf1 | 148 | test_expect_success 'do not complain about existing broken links (tree)' ' |
252a4ee6 | 149 | cat >broken-tree <<-EOF && |
150 | 100644 blob $(test_oid 003) foo | |
a3ba6bf1 JK |
151 | EOF |
152 | tree=$(git mktree --missing <broken-tree) && | |
b068d9a2 | 153 | git gc -q 2>stderr && |
a3ba6bf1 JK |
154 | git cat-file -e $tree && |
155 | test_must_be_empty stderr | |
156 | ' | |
157 | ||
158 | test_expect_success 'do not complain about existing broken links (tag)' ' | |
252a4ee6 | 159 | cat >broken-tag <<-EOF && |
160 | object $(test_oid 004) | |
a3ba6bf1 JK |
161 | type commit |
162 | tag broken | |
163 | tagger whatever <whatever@example.com> 1234 -0000 | |
164 | ||
165 | this is a broken tag | |
166 | EOF | |
167 | tag=$(git hash-object -t tag -w broken-tag) && | |
b068d9a2 | 168 | git gc -q 2>stderr && |
a3ba6bf1 JK |
169 | git cat-file -e $tag && |
170 | test_must_be_empty stderr | |
171 | ' | |
172 | ||
d3038d22 | 173 | test_done |