t / t1506-rev-parse-diagnosis.shon commit Update jk/maint-strbuf-missing-init to builtin/ rename (03f94ae)
   1#!/bin/sh
   2
   3test_description='test git rev-parse diagnosis for invalid argument'
   4
   5exec </dev/null
   6
   7. ./test-lib.sh
   8
   9HASH_file=
  10
  11test_expect_success 'set up basic repo' '
  12        echo one > file.txt &&
  13        mkdir subdir &&
  14        echo two > subdir/file.txt &&
  15        echo three > subdir/file2.txt &&
  16        git add . &&
  17        git commit -m init &&
  18        echo four > index-only.txt &&
  19        git add index-only.txt &&
  20        echo five > disk-only.txt
  21'
  22
  23test_expect_success 'correct file objects' '
  24        HASH_file=$(git rev-parse HEAD:file.txt) &&
  25        git rev-parse HEAD:subdir/file.txt &&
  26        git rev-parse :index-only.txt &&
  27        (cd subdir &&
  28         git rev-parse HEAD:subdir/file2.txt &&
  29         test $HASH_file = $(git rev-parse HEAD:file.txt) &&
  30         test $HASH_file = $(git rev-parse :file.txt) &&
  31         test $HASH_file = $(git rev-parse :0:file.txt) )
  32'
  33
  34test_expect_success 'incorrect revision id' '
  35        test_must_fail git rev-parse foobar:file.txt 2>error &&
  36        grep "Invalid object name '"'"'foobar'"'"'." error &&
  37        test_must_fail git rev-parse foobar 2> error &&
  38        grep "unknown revision or path not in the working tree." error
  39'
  40
  41test_expect_success 'incorrect file in sha1:path' '
  42        test_must_fail git rev-parse HEAD:nothing.txt 2> error &&
  43        grep "fatal: Path '"'"'nothing.txt'"'"' does not exist in '"'"'HEAD'"'"'" error &&
  44        test_must_fail git rev-parse HEAD:index-only.txt 2> error &&
  45        grep "fatal: Path '"'"'index-only.txt'"'"' exists on disk, but not in '"'"'HEAD'"'"'." error &&
  46        (cd subdir &&
  47         test_must_fail git rev-parse HEAD:file2.txt 2> error &&
  48         grep "Did you mean '"'"'HEAD:subdir/file2.txt'"'"'?" error )
  49'
  50
  51test_expect_success 'incorrect file in :path and :N:path' '
  52        test_must_fail git rev-parse :nothing.txt 2> error &&
  53        grep "fatal: Path '"'"'nothing.txt'"'"' does not exist (neither on disk nor in the index)." error &&
  54        test_must_fail git rev-parse :1:nothing.txt 2> error &&
  55        grep "Path '"'"'nothing.txt'"'"' does not exist (neither on disk nor in the index)." error &&
  56        test_must_fail git rev-parse :1:file.txt 2> error &&
  57        grep "Did you mean '"'"':0:file.txt'"'"'?" error &&
  58        (cd subdir &&
  59         test_must_fail git rev-parse :1:file.txt 2> error &&
  60         grep "Did you mean '"'"':0:file.txt'"'"'?" error &&
  61         test_must_fail git rev-parse :file2.txt 2> error &&
  62         grep "Did you mean '"'"':0:subdir/file2.txt'"'"'?" error &&
  63         test_must_fail git rev-parse :2:file2.txt 2> error &&
  64         grep "Did you mean '"'"':0:subdir/file2.txt'"'"'?" error) &&
  65        test_must_fail git rev-parse :disk-only.txt 2> error &&
  66        grep "fatal: Path '"'"'disk-only.txt'"'"' exists on disk, but not in the index." error
  67'
  68
  69test_done