prune: keep objects reachable from recent objects
[git.git] / t / t6501-freshen-objects.sh
blobde941c2cb2211f01a06c5a6dcc60fbefd65f6c7c
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 . ./test-lib.sh
30 # We care about reachability, so we do not want to use
31 # the normal test_commit, which creates extra tags.
32 add () {
33 echo "$1" >"$1" &&
34 git add "$1"
36 commit () {
37 test_tick &&
38 add "$1" &&
39 git commit -m "$1"
42 test_expect_success 'disable reflogs' '
43 git config core.logallrefupdates false &&
44 rm -rf .git/logs
47 test_expect_success 'setup basic history' '
48 commit base
51 test_expect_success 'create and abandon some objects' '
52 git checkout -b experiment &&
53 commit abandon &&
54 git checkout master &&
55 git branch -D experiment
58 test_expect_success 'simulate time passing' '
59 find .git/objects -type f |
60 xargs test-chmtime -v -86400
63 test_expect_success 'start writing new commit with old blob' '
64 tree=$(
65 GIT_INDEX_FILE=index.tmp &&
66 export GIT_INDEX_FILE &&
67 git read-tree HEAD &&
68 add unrelated &&
69 add abandon &&
70 git write-tree
74 test_expect_success 'simultaneous gc' '
75 git gc --prune=12.hours.ago
78 test_expect_success 'finish writing out commit' '
79 commit=$(echo foo | git commit-tree -p HEAD $tree) &&
80 git update-ref HEAD $commit
83 # "abandon" blob should have been rescued by reference from new tree
84 test_expect_success 'repository passes fsck' '
85 git fsck
88 test_done