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