Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/git/blob/master/t/t6501-freshen-objects.sh # git [Ported from github.com/git/git] Sync with Git 2.56.1 Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `master` Branches Tags History `git / t / t6501-freshen-objects.sh` 183 lines ยท 4694 bytes Raw Blame History 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' 28 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main 29 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME 30 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 45 maybe_repack () { 46 case "$title" in 47 loose) 48 : skip repack 49 ;; 50 repack) 51 git repack -ad 52 ;; 53 bitmap) 54 git repack -adb 55 ;; 56 *) 57 echo >&2 "unknown test type in maybe_repack" 58 return 1 59 ;; 60 esac 61 } 62 63 for title in loose repack bitmap 64 do 65 test_expect_success "make repo completely empty ($title)" ' 66 rm -rf .git && 67 git init 68 ' 69 70 test_expect_success "disable reflogs ($title)" ' 71 git config core.logallrefupdates false && 72 git reflog expire --expire=all --all 73 ' 74 75 test_expect_success "setup basic history ($title)" ' 76 commit base 77 ' 78 79 test_expect_success "create and abandon some objects ($title)" ' 80 git checkout -b experiment && 81 commit abandon && 82 maybe_repack && 83 git checkout main && 84 git branch -D experiment 85 ' 86 87 test_expect_success "simulate time passing ($title)" ' 88 test-tool chmtime --get -86400 $(find .git/objects -type f) 89 ' 90 91 test_expect_success "start writing new commit with old blob ($title)" ' 92 tree=$( 93 GIT_INDEX_FILE=index.tmp && 94 export GIT_INDEX_FILE && 95 git read-tree HEAD && 96 add unrelated && 97 add abandon && 98 git write-tree 99 ) 100 ' 101 102 test_expect_success "simultaneous gc ($title)" ' 103 git gc --no-cruft --prune=12.hours.ago 104 ' 105 106 test_expect_success "finish writing out commit ($title)" ' 107 commit=$(echo foo | git commit-tree -p HEAD $tree) && 108 git update-ref HEAD $commit 109 ' 110 111 # "abandon" blob should have been rescued by reference from new tree 112 test_expect_success "repository passes fsck ($title)" ' 113 git fsck 114 ' 115 116 test_expect_success "abandon objects again ($title)" ' 117 git reset --hard HEAD^ && 118 test-tool chmtime --get -86400 $(find .git/objects -type f) 119 ' 120 121 test_expect_success "start writing new commit with same tree ($title)" ' 122 tree=$( 123 GIT_INDEX_FILE=index.tmp && 124 export GIT_INDEX_FILE && 125 git read-tree HEAD && 126 add abandon && 127 add unrelated && 128 git write-tree 129 ) 130 ' 131 132 test_expect_success "simultaneous gc ($title)" ' 133 git gc --no-cruft --prune=12.hours.ago 134 ' 135 136 # tree should have been refreshed by write-tree 137 test_expect_success "finish writing out commit ($title)" ' 138 commit=$(echo foo | git commit-tree -p HEAD $tree) && 139 git update-ref HEAD $commit 140 ' 141 done 142 143 test_expect_success 'do not complain about existing broken links (commit)' ' 144 cat >broken-commit <<-EOF && 145 tree $(test_oid 001) 146 parent $(test_oid 002) 147 author whatever 1234 -0000 148 committer whatever 1234 -0000 149 150 some message 151 EOF 152 commit=$(git hash-object -t commit -w broken-commit) && 153 git gc --no-cruft -q 2>stderr && 154 git cat-file -e $commit && 155 test_must_be_empty stderr 156 ' 157 158 test_expect_success 'do not complain about existing broken links (tree)' ' 159 cat >broken-tree <<-EOF && 160 100644 blob $(test_oid 003) foo 161 EOF 162 tree=$(git mktree --missing stderr && 164 git cat-file -e $tree && 165 test_must_be_empty stderr 166 ' 167 168 test_expect_success 'do not complain about existing broken links (tag)' ' 169 cat >broken-tag <<-EOF && 170 object $(test_oid 004) 171 type commit 172 tag broken 173 tagger whatever 1234 -0000 174 175 this is a broken tag 176 EOF 177 tag=$(git hash-object -t tag -w broken-tag) && 178 git gc --no-cruft -q 2>stderr && 179 git cat-file -e $tag && 180 test_must_be_empty stderr 181 ' 182 183 test_done