1#!/bin/sh
2
3test_description='.git file
4
5Verify that plumbing commands work when .git is a file
6'
7. ./test-lib.sh
8
9objpath() {
10 echo "$1" | sed -e 's|\(..\)|\1/|'
11}
12
13test_expect_success 'initial setup' '
14 REAL="$(pwd)/.real" &&
15 mv .git "$REAL"
16'
17
18test_expect_success 'bad setup: invalid .git file format' '
19 echo "gitdir $REAL" >.git &&
20 test_must_fail git rev-parse 2>.err &&
21 grep "Invalid gitfile format" .err
22'
23
24test_expect_success 'bad setup: invalid .git file path' '
25 echo "gitdir: $REAL.not" >.git &&
26 test_must_fail git rev-parse 2>.err &&
27 grep "Not a git repository" .err
28'
29
30test_expect_success 'final setup + check rev-parse --git-dir' '
31 echo "gitdir: $REAL" >.git &&
32 test "$REAL" = "$(git rev-parse --git-dir)"
33'
34
35test_expect_success 'check hash-object' '
36 echo "foo" >bar &&
37 SHA=$(cat bar | git hash-object -w --stdin) &&
38 test_path_is_file "$REAL/objects/$(objpath $SHA)"
39'
40
41test_expect_success 'check cat-file' '
42 git cat-file blob $SHA >actual &&
43 test_cmp bar actual
44'
45
46test_expect_success 'check update-index' '
47 test_path_is_missing "$REAL/index" &&
48 rm -f "$REAL/objects/$(objpath $SHA)" &&
49 git update-index --add bar &&
50 test_path_is_file "$REAL/index" &&
51 test_path_is_file "$REAL/objects/$(objpath $SHA)"
52'
53
54test_expect_success 'check write-tree' '
55 SHA=$(git write-tree) &&
56 test_path_is_file "$REAL/objects/$(objpath $SHA)"
57'
58
59test_expect_success 'check commit-tree' '
60 SHA=$(echo "commit bar" | git commit-tree $SHA) &&
61 test_path_is_file "$REAL/objects/$(objpath $SHA)"
62'
63
64test_expect_success 'check rev-list' '
65 echo $SHA >"$REAL/HEAD" &&
66 test "$SHA" = "$(git rev-list HEAD)"
67'
68
69test_expect_success 'setup_git_dir twice in subdir' '
70 git init sgd &&
71 (
72 cd sgd &&
73 git config alias.lsfi ls-files &&
74 mv .git .realgit &&
75 echo "gitdir: .realgit" >.git &&
76 mkdir subdir &&
77 cd subdir &&
78 >foo &&
79 git add foo &&
80 git lsfi >actual &&
81 echo foo >expected &&
82 test_cmp expected actual
83 )
84'
85
86test_expect_success 'enter_repo non-strict mode' '
87 test_create_repo enter_repo &&
88 (
89 cd enter_repo &&
90 test_tick &&
91 test_commit foo &&
92 mv .git .realgit &&
93 echo "gitdir: .realgit" >.git
94 ) &&
95 git ls-remote enter_repo >actual &&
96 cat >expected <<-\EOF &&
97 946e985ab20de757ca5b872b16d64e92ff3803a9 HEAD
98 946e985ab20de757ca5b872b16d64e92ff3803a9 refs/heads/master
99 946e985ab20de757ca5b872b16d64e92ff3803a9 refs/tags/foo
100 EOF
101 test_cmp expected actual
102'
103
104test_expect_success 'enter_repo linked checkout' '
105 (
106 cd enter_repo &&
107 git worktree add ../foo refs/tags/foo
108 ) &&
109 git ls-remote foo >actual &&
110 cat >expected <<-\EOF &&
111 946e985ab20de757ca5b872b16d64e92ff3803a9 HEAD
112 946e985ab20de757ca5b872b16d64e92ff3803a9 refs/heads/master
113 946e985ab20de757ca5b872b16d64e92ff3803a9 refs/tags/foo
114 EOF
115 test_cmp expected actual
116'
117
118test_expect_success 'enter_repo strict mode' '
119 git ls-remote --upload-pack="git upload-pack --strict" foo/.git >actual &&
120 cat >expected <<-\EOF &&
121 946e985ab20de757ca5b872b16d64e92ff3803a9 HEAD
122 946e985ab20de757ca5b872b16d64e92ff3803a9 refs/heads/master
123 946e985ab20de757ca5b872b16d64e92ff3803a9 refs/tags/foo
124 EOF
125 test_cmp expected actual
126'
127
128test_done