core.hidedotfiles: hide '.git' dir by default
[git/dscho.git] / t / t0002-gitfile.sh
blobcb144258ccc3f32025c4b7beba6ac02c427612d8
1 #!/bin/sh
3 test_description='.git file
5 Verify that plumbing commands work when .git is a file
7 . ./test-lib.sh
9 objpath() {
10 echo "$1" | sed -e 's|\(..\)|\1/|'
13 objck() {
14 p=$(objpath "$1")
15 if test ! -f "$REAL/objects/$p"
16 then
17 echo "Object not found: $REAL/objects/$p"
18 false
23 test_expect_success 'initial setup' '
24 REAL="$(pwd)/.real" &&
25 mv .git "$REAL"
28 test_expect_success 'bad setup: invalid .git file format' '
29 echo "gitdir $REAL" >.git &&
30 if git rev-parse 2>.err
31 then
32 echo "git rev-parse accepted an invalid .git file"
33 false
34 fi &&
35 if ! grep "Invalid gitfile format" .err
36 then
37 echo "git rev-parse returned wrong error"
38 false
42 test_expect_success 'bad setup: invalid .git file path' '
43 echo "gitdir: $REAL.not" >.git &&
44 if git rev-parse 2>.err
45 then
46 echo "git rev-parse accepted an invalid .git file path"
47 false
48 fi &&
49 if ! grep "Not a git repository" .err
50 then
51 echo "git rev-parse returned wrong error"
52 false
56 test_expect_success 'final setup + check rev-parse --git-dir' '
57 echo "gitdir: $REAL" >.git &&
58 test "$REAL" = "$(git rev-parse --git-dir)"
61 test_expect_success 'check hash-object' '
62 echo "foo" >bar &&
63 SHA=$(cat bar | git hash-object -w --stdin) &&
64 objck $SHA
67 test_expect_success 'check cat-file' '
68 git cat-file blob $SHA >actual &&
69 test_cmp bar actual
72 test_expect_success 'check update-index' '
73 if test -f "$REAL/index"
74 then
75 echo "Hmm, $REAL/index exists?"
76 false
77 fi &&
78 rm -f "$REAL/objects/$(objpath $SHA)" &&
79 git update-index --add bar &&
80 if ! test -f "$REAL/index"
81 then
82 echo "$REAL/index not found"
83 false
84 fi &&
85 objck $SHA
88 test_expect_success 'check write-tree' '
89 SHA=$(git write-tree) &&
90 objck $SHA
93 test_expect_success 'check commit-tree' '
94 SHA=$(echo "commit bar" | git commit-tree $SHA) &&
95 objck $SHA
98 test_expect_success 'check rev-list' '
99 echo $SHA >"$REAL/HEAD" &&
100 test "$SHA" = "$(git rev-list HEAD)"
103 test_done