3 test_description
="git-hash-object"
7 echo_without_newline
() {
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
18 test_expect_success
'blob exists in database' "
23 hello_content
="Hello World"
24 hello_sha1
=5e1c309dae7f45e0f39b1bf3ac3cd9db12e7d689
26 example_content
="This is an example"
27 example_sha1
=ddd3f836d3e3fbb7ae289aa9ae83536f76956399
30 echo_without_newline
"$hello_content" > hello
31 echo_without_newline
"$example_content" > example
36 test_create_repo
$test_repo
51 test_expect_success
"multiple '--stdin's are rejected" '
52 echo example | test_must_fail git hash-object --stdin --stdin
55 test_expect_success
"Can't use --stdin and --stdin-paths together" '
56 echo example | test_must_fail git hash-object --stdin --stdin-paths &&
57 echo example | test_must_fail git hash-object --stdin-paths --stdin
60 test_expect_success
"Can't pass filenames as arguments with --stdin-paths" '
61 echo example | test_must_fail git hash-object --stdin-paths hello
64 test_expect_success
"Can't use --path with --stdin-paths" '
65 echo example | test_must_fail git hash-object --stdin-paths --path=foo
72 test_expect_success
'hash a file' '
73 test $hello_sha1 = $(git hash-object hello)
76 test_blob_does_not_exist
$hello_sha1
78 test_expect_success
'hash from stdin' '
79 test $example_sha1 = $(git hash-object --stdin < example)
82 test_blob_does_not_exist
$example_sha1
84 test_expect_success
'hash a file and write to database' '
85 test $hello_sha1 = $(git hash-object -w hello)
88 test_blob_exists
$hello_sha1
90 test_expect_success
'git hash-object --stdin file1 <file0 first operates on file0, then file1' '
92 obname0=$(echo bar | git hash-object --stdin) &&
93 obname1=$(git hash-object file1) &&
94 obname0new=$(echo bar | git hash-object --stdin file1 | sed -n -e 1p) &&
95 obname1new=$(echo bar | git hash-object --stdin file1 | sed -n -e 2p) &&
96 test "$obname0" = "$obname0new" &&
97 test "$obname1" = "$obname1new"
100 test_expect_success
'check that appropriate filter is invoke when --path is used' '
101 echo fooQ | tr Q "\\015" >file0 &&
103 echo "file0 -crlf" >.gitattributes &&
104 echo "file1 crlf" >>.gitattributes &&
105 git config core.autocrlf true &&
106 file0_sha=$(git hash-object file0) &&
107 file1_sha=$(git hash-object file1) &&
108 test "$file0_sha" != "$file1_sha" &&
109 path1_sha=$(git hash-object --path=file1 file0) &&
110 path0_sha=$(git hash-object --path=file0 file1) &&
111 test "$file0_sha" = "$path0_sha" &&
112 test "$file1_sha" = "$path1_sha" &&
113 path1_sha=$(cat file0 | git hash-object --path=file1 --stdin) &&
114 path0_sha=$(cat file1 | git hash-object --path=file0 --stdin) &&
115 test "$file0_sha" = "$path0_sha" &&
116 test "$file1_sha" = "$path1_sha" &&
117 git config --unset core.autocrlf
122 for args
in "-w --stdin" "--stdin -w"; do
125 test_expect_success
"hash from stdin and write to database ($args)" '
126 test $example_sha1 = $(git hash-object $args < example)
129 test_blob_exists
$example_sha1
140 test_expect_success
"hash two files with names on stdin" '
141 test "$sha1s" = "$(echo_without_newline "$filenames" | git hash-object --stdin-paths)"
144 for args
in "-w --stdin-paths" "--stdin-paths -w"; do
147 test_expect_success
"hash two files with names on stdin and write to database ($args)" '
148 test "$sha1s" = "$(echo_without_newline "$filenames" | git hash-object $args)"
151 test_blob_exists
$hello_sha1
152 test_blob_exists
$example_sha1