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/t0090-cache-tree.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 / t0090-cache-tree.sh` 302 lines ยท 7232 bytes Raw Blame History 1 #!/bin/sh 2 3 test_description="Test whether cache-tree is properly updated 4 5 Tests whether various commands properly update and/or rewrite the 6 cache-tree extension. 7 " 8 9 . ./test-lib.sh 10 11 cmp_cache_tree () { 12 test-tool dump-cache-tree | sed -e '/#(ref)/d' >actual && 13 sed "s/$OID_REGEX/SHA/" filtered && 14 test_cmp "$1" filtered && 15 rm filtered 16 } 17 18 # We don't bother with actually checking the SHA1: 19 # test-tool dump-cache-tree already verifies that all existing data is 20 # correct. 21 generate_expected_cache_tree () { 22 pathspec="$1" && 23 dir="$2${2:+/}" && 24 git ls-tree --name-only HEAD -- "$pathspec" >files && 25 git ls-tree --name-only -d HEAD -- "$pathspec" >subtrees && 26 printf "SHA %s (%d entries, %d subtrees)\n" "$dir" $(wc -l expect && 35 cmp_cache_tree expect && 36 rm expect actual files subtrees && 37 git status --porcelain -- ':!status' ':!expected.status' >status && 38 if test -n "$1" 39 then 40 test_cmp "$1" status 41 else 42 test_must_be_empty status 43 fi 44 } 45 46 test_invalid_cache_tree () { 47 printf "invalid %s ()\n" "" "$@" >expect && 48 test-tool dump-cache-tree | 49 sed -n -e "s/[0-9]* subtrees//" -e '/#(ref)/d' -e '/^invalid /p' >actual && 50 test_cmp expect actual 51 } 52 53 test_no_cache_tree () { 54 >expect && 55 cmp_cache_tree expect 56 } 57 58 test_expect_success 'initial commit has cache-tree' ' 59 test_commit foo && 60 test_cache_tree 61 ' 62 63 test_expect_success 'read-tree HEAD establishes cache-tree' ' 64 git read-tree HEAD && 65 test_cache_tree 66 ' 67 68 test_expect_success 'git-add invalidates cache-tree' ' 69 test_when_finished "git reset --hard; git read-tree HEAD" && 70 echo "I changed this file" >foo && 71 git add foo && 72 test_invalid_cache_tree 73 ' 74 75 test_expect_success 'git-add in subdir invalidates cache-tree' ' 76 test_when_finished "git reset --hard; git read-tree HEAD" && 77 mkdir dirx && 78 echo "I changed this file" >dirx/foo && 79 git add dirx/foo && 80 test_invalid_cache_tree 81 ' 82 83 test_expect_success 'git-add in subdir does not invalidate sibling cache-tree' ' 84 git tag no-children && 85 test_when_finished "git reset --hard no-children; git read-tree HEAD" && 86 mkdir dir1 dir2 && 87 test_commit dir1/a && 88 test_commit dir2/b && 89 echo "I changed this file" >dir1/a && 90 test_when_finished "rm before" && 91 cat >before <<-\EOF && 92 SHA (3 entries, 2 subtrees) 93 SHA dir1/ (1 entries, 0 subtrees) 94 SHA dir2/ (1 entries, 0 subtrees) 95 EOF 96 cmp_cache_tree before && 97 echo "I changed this file" >dir1/a && 98 git add dir1/a && 99 cat >expect <<-\EOF && 100 invalid (2 subtrees) 101 invalid dir1/ (0 subtrees) 102 SHA dir2/ (1 entries, 0 subtrees) 103 EOF 104 cmp_cache_tree expect 105 ' 106 107 test_expect_success 'update-index invalidates cache-tree' ' 108 test_when_finished "git reset --hard; git read-tree HEAD" && 109 echo "I changed this file" >foo && 110 git update-index --add foo && 111 test_invalid_cache_tree 112 ' 113 114 test_expect_success 'write-tree establishes cache-tree' ' 115 test-tool scrap-cache-tree && 116 git write-tree && 117 test_cache_tree 118 ' 119 120 test_expect_success 'test-tool scrap-cache-tree works' ' 121 git read-tree HEAD && 122 test-tool scrap-cache-tree && 123 test_no_cache_tree 124 ' 125 126 test_expect_success 'second commit has cache-tree' ' 127 test_commit bar && 128 test_cache_tree 129 ' 130 131 test_expect_success 'commit --interactive gives cache-tree on partial commit' ' 132 test_when_finished "git reset --hard" && 133 cat <<-\EOT >foo.c && 134 int foo() 135 { 136 return 42; 137 } 138 int bar() 139 { 140 return 42; 141 } 142 EOT 143 git add foo.c && 144 test_invalid_cache_tree && 145 git commit -m "add a file" && 146 test_cache_tree && 147 cat <<-\EOT >foo.c && 148 int foo() 149 { 150 return 43; 151 } 152 int bar() 153 { 154 return 44; 155 } 156 EOT 157 test_write_lines p 1 "" s n y q | 158 git commit --interactive -m foo && 159 cat <<-\EOF >expected.status && 160 M foo.c 161 EOF 162 test_cache_tree expected.status 163 ' 164 165 test_expect_success 'commit -p with shrinking cache-tree' ' 166 mkdir -p deep/very-long-subdir && 167 echo content >deep/very-long-subdir/file && 168 git add deep && 169 git commit -m add && 170 git rm -r deep && 171 172 before=$(wc -c <.git/index) && 173 git commit -m delete -p && 174 after=$(wc -c <.git/index) && 175 176 # double check that the index shrank 177 test $before -gt $after && 178 179 # and that our index was not corrupted 180 git fsck 181 ' 182 183 test_expect_success 'commit in child dir has cache-tree' ' 184 mkdir dir && 185 >dir/child.t && 186 git add dir/child.t && 187 git commit -m dir/child.t && 188 test_cache_tree 189 ' 190 191 test_expect_success 'reset --hard gives cache-tree' ' 192 test-tool scrap-cache-tree && 193 git reset --hard && 194 test_cache_tree 195 ' 196 197 test_expect_success 'reset --hard without index gives cache-tree' ' 198 rm -f .git/index && 199 git clean -fd && 200 git reset --hard && 201 test_cache_tree 202 ' 203 204 test_expect_success 'checkout gives cache-tree' ' 205 git tag current && 206 git checkout HEAD^ && 207 test_cache_tree 208 ' 209 210 test_expect_success 'checkout -b gives cache-tree' ' 211 git checkout current && 212 git checkout -b prev HEAD^ && 213 test_cache_tree 214 ' 215 216 test_expect_success 'checkout -B gives cache-tree' ' 217 git checkout current && 218 git checkout -B prev HEAD^ && 219 test_cache_tree 220 ' 221 222 test_expect_success 'merge --ff-only maintains cache-tree' ' 223 git checkout current && 224 git checkout -b changes && 225 test_commit llamas && 226 test_commit pachyderm && 227 test_cache_tree && 228 git checkout current && 229 test_cache_tree && 230 git merge --ff-only changes && 231 test_cache_tree 232 ' 233 234 test_expect_success 'merge maintains cache-tree' ' 235 git checkout current && 236 git checkout -b changes2 && 237 test_commit alpacas && 238 test_cache_tree && 239 git checkout current && 240 test_commit struthio && 241 test_cache_tree && 242 git merge changes2 && 243 test_cache_tree 244 ' 245 246 test_expect_success 'partial commit gives cache-tree' ' 247 git checkout -b partial no-children && 248 test_commit one && 249 test_commit two && 250 echo "some change" >one.t && 251 git add one.t && 252 echo "some other change" >two.t && 253 git commit two.t -m partial && 254 cat <<-\EOF >expected.status && 255 M one.t 256 EOF 257 test_cache_tree expected.status 258 ' 259 260 test_expect_success 'no phantom error when switching trees' ' 261 mkdir newdir && 262 >newdir/one && 263 git add newdir/one && 264 git checkout 2>errors && 265 test_must_be_empty errors 266 ' 267 268 test_expect_success 'switching trees does not invalidate shared index' ' 269 ( 270 sane_unset GIT_TEST_SPLIT_INDEX && 271 git update-index --split-index && 272 >split && 273 git add split && 274 test-tool dump-split-index .git/index | grep -v ^own >before && 275 git commit -m "as-is" && 276 test-tool dump-split-index .git/index | grep -v ^own >after && 277 test_cmp before after 278 ) 279 ' 280 281 test_expect_success 'cache-tree is used by write-tree when valid' ' 282 test_commit use-valid && 283 284 # write-tree with a valid cache-tree should skip cache_tree_update 285 GIT_TRACE2_PERF="$(pwd)/trace.output" git write-tree && 286 test_grep ! region_enter.*cache_tree.*update trace.output 287 ' 288 289 test_expect_success 'write-tree succeeds while the index is locked' ' 290 test_when_finished "rm -f .git/index.lock" && 291 test_commit locked && 292 >uncommitted && 293 git add uncommitted && 294 >.git/index.lock && 295 git write-tree >actual && 296 test_path_is_file .git/index.lock && 297 rm .git/index.lock && 298 git write-tree >expect && 299 test_cmp expect actual 300 ' 301 302 test_done