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/t1007-hash-object.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 / t1007-hash-object.sh` 300 lines ยท 8695 bytes Raw Blame History 1 #!/bin/sh 2 3 test_description="git hash-object" 4 5 . ./test-lib.sh 6 7 echo_without_newline() { 8 printf '%s' "$*" 9 } 10 11 test_blob_does_not_exist() { 12 test_expect_success 'blob does not exist in database' " 13 test_must_fail git cat-file blob $1 14 " 15 } 16 17 test_blob_exists() { 18 test_expect_success 'blob exists in database' " 19 git cat-file blob $1 20 " 21 } 22 23 hello_content="Hello World" 24 example_content="This is an example" 25 26 setup_repo() { 27 echo_without_newline "$hello_content" > hello 28 echo_without_newline "$example_content" > example 29 } 30 31 test_repo=test 32 push_repo() { 33 git init --quiet $test_repo 34 cd $test_repo 35 36 setup_repo 37 } 38 39 pop_repo() { 40 cd .. 41 rm -rf $test_repo 42 } 43 44 test_expect_success 'setup' ' 45 setup_repo && 46 test_oid_cache <<-EOF 47 hello sha1:`5e1c309dae7f45e0f39b1bf3ac3cd9db12e7d689` 48 hello sha256:`1e3b6c04d2eeb2b3e45c8a330445404c0b7cc7b257e2b097167d26f5230090c4` 49 50 example sha1:`ddd3f836d3e3fbb7ae289aa9ae83536f76956399` 51 example sha256:`b44fe1fe65589848253737db859bd490453510719d7424daab03daf0767b85ae` 52 53 large5GB sha1:`0be2be10a4c8764f32c4bf372a98edc731a4b204` 54 large5GB sha256:`dc18ca621300c8d3cfa505a275641ebab00de189859e022a975056882d313e64` 55 EOF 56 ' 57 58 # Argument checking 59 60 test_expect_success "multiple '--stdin's are rejected" ' 61 echo example | test_must_fail git hash-object --stdin --stdin 62 ' 63 64 test_expect_success "Can't use --stdin and --stdin-paths together" ' 65 echo example | test_must_fail git hash-object --stdin --stdin-paths && 66 echo example | test_must_fail git hash-object --stdin-paths --stdin 67 ' 68 69 test_expect_success "Can't pass filenames as arguments with --stdin-paths" ' 70 echo example | test_must_fail git hash-object --stdin-paths hello 71 ' 72 73 test_expect_success "Can't use --path with --stdin-paths" ' 74 echo example | test_must_fail git hash-object --stdin-paths --path=foo 75 ' 76 77 test_expect_success "Can't use --path with --no-filters" ' 78 test_must_fail git hash-object --no-filters --path=foo 79 ' 80 81 # Behavior 82 83 push_repo 84 85 test_expect_success 'hash a file' ' 86 test "$(test_oid hello)" = $(git hash-object hello) 87 ' 88 89 test_blob_does_not_exist "$(test_oid hello)" 90 91 test_expect_success 'hash from stdin' ' 92 test "$(test_oid example)" = $(git hash-object --stdin < example) 93 ' 94 95 test_blob_does_not_exist "$(test_oid example)" 96 97 test_expect_success 'hash a file and write to database' ' 98 test "$(test_oid hello)" = $(git hash-object -w hello) 99 ' 100 101 test_blob_exists "$(test_oid hello)" 102 103 test_expect_success 'git hash-object --stdin file1 file1 && 105 obname0=$(echo bar | git hash-object --stdin) && 106 obname1=$(git hash-object file1) && 107 obname0new=$(echo bar | git hash-object --stdin file1 | sed -n -e 1p) && 108 obname1new=$(echo bar | git hash-object --stdin file1 | sed -n -e 2p) && 109 test "$obname0" = "$obname0new" && 110 test "$obname1" = "$obname1new" 111 ' 112 113 test_expect_success 'set up crlf tests' ' 114 echo fooQ | tr Q "\\015" >file0 && 115 cp file0 file1 && 116 echo "file0 -crlf" >.gitattributes && 117 echo "file1 crlf" >>.gitattributes && 118 git config core.autocrlf true && 119 file0_sha=$(git hash-object file0) && 120 file1_sha=$(git hash-object file1) && 121 test "$file0_sha" != "$file1_sha" 122 ' 123 124 test_expect_success 'check that appropriate filter is invoke when --path is used' ' 125 path1_sha=$(git hash-object --path=file1 file0) && 126 path0_sha=$(git hash-object --path=file0 file1) && 127 test "$file0_sha" = "$path0_sha" && 128 test "$file1_sha" = "$path1_sha" && 129 path1_sha=$(git hash-object --path=file1 --stdin malformed-tree && 207 test_must_fail git hash-object -t tree malformed-tree 2>err && 208 test_grep "too-short tree object" err 209 ' 210 211 test_expect_success PERL_TEST_HELPERS 'malformed mode in tree' ' 212 hex_oid=$(echo foo | git hash-object --stdin -w) && 213 bin_oid=$(echo $hex_oid | hex2oct) && 214 printf "`9100644` \0$bin_oid" >tree-with-malformed-mode && 215 test_must_fail git hash-object -t tree tree-with-malformed-mode 2>err && 216 test_grep "malformed mode in tree entry" err 217 ' 218 219 test_expect_success PERL_TEST_HELPERS 'empty filename in tree' ' 220 hex_oid=$(echo foo | git hash-object --stdin -w) && 221 bin_oid=$(echo $hex_oid | hex2oct) && 222 printf "100644 \0$bin_oid" >tree-with-empty-filename && 223 test_must_fail git hash-object -t tree tree-with-empty-filename 2>err && 224 test_grep "empty filename in tree entry" err 225 ' 226 227 test_expect_success PERL_TEST_HELPERS 'duplicate filename in tree' ' 228 hex_oid=$(echo foo | git hash-object --stdin -w) && 229 bin_oid=$(echo $hex_oid | hex2oct) && 230 { 231 printf "100644 file\0$bin_oid" && 232 printf "100644 file\0$bin_oid" 233 } >tree-with-duplicate-filename && 234 test_must_fail git hash-object -t tree tree-with-duplicate-filename 2>err && 235 test_grep "duplicateEntries" err 236 ' 237 238 test_expect_success 'corrupt commit' ' 239 test_must_fail git hash-object -t commit --stdin actual && 260 echo "$(test_oid --hash=builtin hello)" >expect && 261 test_cmp expect actual 262 ' 263 264 test_expect_success EXPENSIVE,SIZE_T_IS_64BIT \ 265 'files over 4GB hash literally' ' 266 test-tool genzeros $((5*1024*1024*1024)) >big && 267 test_oid large5GB >expect && 268 git hash-object --stdin --literally actual && 269 test_cmp expect actual 270 ' 271 272 test_expect_success EXPENSIVE,SIZE_T_IS_64BIT \ 273 'files over 4GB hash correctly via --stdin' ' 274 { test -f big || test-tool genzeros $((5*1024*1024*1024)) >big; } && 275 test_oid large5GB >expect && 276 git hash-object --stdin actual && 277 test_cmp expect actual 278 ' 279 280 test_expect_success EXPENSIVE,SIZE_T_IS_64BIT \ 281 'files over 4GB hash correctly' ' 282 { test -f big || test-tool genzeros $((5*1024*1024*1024)) >big; } && 283 test_oid large5GB >expect && 284 git hash-object -- big >actual && 285 test_cmp expect actual 286 ' 287 288 # This clean filter does nothing, other than excercising the interface. 289 # We ensure that cleaning doesn't mangle large files on 64-bit Windows. 290 test_expect_success EXPENSIVE,SIZE_T_IS_64BIT \ 291 'hash filtered files over 4GB correctly' ' 292 { test -f big || test-tool genzeros $((5*1024*1024*1024)) >big; } && 293 test_oid large5GB >expect && 294 test_config filter.null-filter.clean "cat" && 295 echo "big filter=null-filter" >.gitattributes && 296 git hash-object -- big >actual && 297 test_cmp expect actual 298 ' 299 300 test_done