]> git.ipfire.org Git - thirdparty/git.git/blobdiff - t/t1007-hash-object.sh
The ninth batch
[thirdparty/git.git] / t / t1007-hash-object.sh
index ac5ad8c7402d2bd3f43d38e5a676d864ea415d37..d73a5cc23705e2b697d56f961b27a6815725f8c4 100755 (executable)
@@ -124,8 +124,8 @@ test_expect_success 'check that appropriate filter is invoke when --path is used
        path0_sha=$(git hash-object --path=file0 file1) &&
        test "$file0_sha" = "$path0_sha" &&
        test "$file1_sha" = "$path1_sha" &&
-       path1_sha=$(cat file0 | git hash-object --path=file1 --stdin) &&
-       path0_sha=$(cat file1 | git hash-object --path=file0 --stdin) &&
+       path1_sha=$(git hash-object --path=file1 --stdin <file0) &&
+       path0_sha=$(git hash-object --path=file0 --stdin <file1) &&
        test "$file0_sha" = "$path0_sha" &&
        test "$file1_sha" = "$path1_sha"
 '
@@ -154,7 +154,7 @@ test_expect_success '--path works in a subdirectory' '
 test_expect_success 'check that --no-filters option works' '
        nofilters_file1=$(git hash-object --no-filters file1) &&
        test "$file0_sha" = "$nofilters_file1" &&
-       nofilters_file1=$(cat file1 | git hash-object --stdin) &&
+       nofilters_file1=$(git hash-object --stdin <file1) &&
        test "$file0_sha" = "$nofilters_file1"
 '
 
@@ -203,23 +203,34 @@ done
 test_expect_success 'too-short tree' '
        echo abc >malformed-tree &&
        test_must_fail git hash-object -t tree malformed-tree 2>err &&
-       test_i18ngrep "too-short tree object" err
+       grep "too-short tree object" err
 '
 
 test_expect_success 'malformed mode in tree' '
-       hex_sha1=$(echo foo | git hash-object --stdin -w) &&
-       bin_sha1=$(echo $hex_sha1 | hex2oct) &&
-       printf "9100644 \0$bin_sha1" >tree-with-malformed-mode &&
+       hex_oid=$(echo foo | git hash-object --stdin -w) &&
+       bin_oid=$(echo $hex_oid | hex2oct) &&
+       printf "9100644 \0$bin_oid" >tree-with-malformed-mode &&
        test_must_fail git hash-object -t tree tree-with-malformed-mode 2>err &&
-       test_i18ngrep "malformed mode in tree entry" err
+       grep "malformed mode in tree entry" err
 '
 
 test_expect_success 'empty filename in tree' '
-       hex_sha1=$(echo foo | git hash-object --stdin -w) &&
-       bin_sha1=$(echo $hex_sha1 | hex2oct) &&
-       printf "100644 \0$bin_sha1" >tree-with-empty-filename &&
+       hex_oid=$(echo foo | git hash-object --stdin -w) &&
+       bin_oid=$(echo $hex_oid | hex2oct) &&
+       printf "100644 \0$bin_oid" >tree-with-empty-filename &&
        test_must_fail git hash-object -t tree tree-with-empty-filename 2>err &&
-       test_i18ngrep "empty filename in tree entry" err
+       grep "empty filename in tree entry" err
+'
+
+test_expect_success 'duplicate filename in tree' '
+       hex_oid=$(echo foo | git hash-object --stdin -w) &&
+       bin_oid=$(echo $hex_oid | hex2oct) &&
+       {
+               printf "100644 file\0$bin_oid" &&
+               printf "100644 file\0$bin_oid"
+       } >tree-with-duplicate-filename &&
+       test_must_fail git hash-object -t tree tree-with-duplicate-filename 2>err &&
+       grep "duplicateEntries" err
 '
 
 test_expect_success 'corrupt commit' '
@@ -249,4 +260,10 @@ test_expect_success '--literally with extra-long type' '
        echo example | git hash-object -t $t --literally --stdin
 '
 
+test_expect_success '--stdin outside of repository (uses SHA-1)' '
+       nongit git hash-object --stdin <hello >actual &&
+       echo "$(test_oid --hash=sha1 hello)" >expect &&
+       test_cmp expect actual
+'
+
 test_done