format-patch: ensure that --rfc and -k are mutually exclusive
[alt-git.git] / t / t6501-freshen-objects.sh
blob4521508b83a6560e6d025dca1750838f083fdc89
1 #!/bin/sh
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.
7 # We're going to do two things that are a little bit "fake" to
8 # help make our simulation easier:
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.
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).
27 test_description='check pruning of dependent objects'
28 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
29 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
31 TEST_PASSES_SANITIZE_LEAK=true
32 . ./test-lib.sh
34 # We care about reachability, so we do not want to use
35 # the normal test_commit, which creates extra tags.
36 add () {
37 echo "$1" >"$1" &&
38 git add "$1"
40 commit () {
41 test_tick &&
42 add "$1" &&
43 git commit -m "$1"
46 maybe_repack () {
47 case "$title" in
48 loose)
49 : skip repack
51 repack)
52 git repack -ad
54 bitmap)
55 git repack -adb
58 echo >&2 "unknown test type in maybe_repack"
59 return 1
61 esac
64 for title in loose repack bitmap
66 test_expect_success "make repo completely empty ($title)" '
67 rm -rf .git &&
68 git init
71 test_expect_success "disable reflogs ($title)" '
72 git config core.logallrefupdates false &&
73 git reflog expire --expire=all --all
76 test_expect_success "setup basic history ($title)" '
77 commit base
80 test_expect_success "create and abandon some objects ($title)" '
81 git checkout -b experiment &&
82 commit abandon &&
83 maybe_repack &&
84 git checkout main &&
85 git branch -D experiment
88 test_expect_success "simulate time passing ($title)" '
89 test-tool chmtime --get -86400 $(find .git/objects -type f)
92 test_expect_success "start writing new commit with old blob ($title)" '
93 tree=$(
94 GIT_INDEX_FILE=index.tmp &&
95 export GIT_INDEX_FILE &&
96 git read-tree HEAD &&
97 add unrelated &&
98 add abandon &&
99 git write-tree
103 test_expect_success "simultaneous gc ($title)" '
104 git gc --no-cruft --prune=12.hours.ago
107 test_expect_success "finish writing out commit ($title)" '
108 commit=$(echo foo | git commit-tree -p HEAD $tree) &&
109 git update-ref HEAD $commit
112 # "abandon" blob should have been rescued by reference from new tree
113 test_expect_success "repository passes fsck ($title)" '
114 git fsck
117 test_expect_success "abandon objects again ($title)" '
118 git reset --hard HEAD^ &&
119 test-tool chmtime --get -86400 $(find .git/objects -type f)
122 test_expect_success "start writing new commit with same tree ($title)" '
123 tree=$(
124 GIT_INDEX_FILE=index.tmp &&
125 export GIT_INDEX_FILE &&
126 git read-tree HEAD &&
127 add abandon &&
128 add unrelated &&
129 git write-tree
133 test_expect_success "simultaneous gc ($title)" '
134 git gc --no-cruft --prune=12.hours.ago
137 # tree should have been refreshed by write-tree
138 test_expect_success "finish writing out commit ($title)" '
139 commit=$(echo foo | git commit-tree -p HEAD $tree) &&
140 git update-ref HEAD $commit
142 done
144 test_expect_success 'do not complain about existing broken links (commit)' '
145 cat >broken-commit <<-EOF &&
146 tree $(test_oid 001)
147 parent $(test_oid 002)
148 author whatever <whatever@example.com> 1234 -0000
149 committer whatever <whatever@example.com> 1234 -0000
151 some message
153 commit=$(git hash-object -t commit -w broken-commit) &&
154 git gc --no-cruft -q 2>stderr &&
155 git cat-file -e $commit &&
156 test_must_be_empty stderr
159 test_expect_success 'do not complain about existing broken links (tree)' '
160 cat >broken-tree <<-EOF &&
161 100644 blob $(test_oid 003) foo
163 tree=$(git mktree --missing <broken-tree) &&
164 git gc --no-cruft -q 2>stderr &&
165 git cat-file -e $tree &&
166 test_must_be_empty stderr
169 test_expect_success 'do not complain about existing broken links (tag)' '
170 cat >broken-tag <<-EOF &&
171 object $(test_oid 004)
172 type commit
173 tag broken
174 tagger whatever <whatever@example.com> 1234 -0000
176 this is a broken tag
178 tag=$(git hash-object -t tag -w broken-tag) &&
179 git gc --no-cruft -q 2>stderr &&
180 git cat-file -e $tag &&
181 test_must_be_empty stderr
184 test_done