Git fork
1#!/bin/sh
2
3test_description='.git file
4
5Verify that plumbing commands work when .git is a file
6'
7GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
8export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
9
10. ./test-lib.sh
11
12objpath() {
13 echo "$1" | sed -e 's|\(..\)|\1/|'
14}
15
16test_expect_success 'initial setup' '
17 REAL="$(pwd)/.real" &&
18 mv .git "$REAL"
19'
20
21test_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
27test_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
33test_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
40test_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
46test_expect_success 'check cat-file' '
47 git cat-file blob $SHA >actual &&
48 test_cmp bar actual
49'
50
51test_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
59test_expect_success 'check write-tree' '
60 SHA=$(git write-tree) &&
61 test_path_is_file "$REAL/objects/$(objpath $SHA)"
62'
63
64test_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
69test_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
76test_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
93test_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
112test_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
127test_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
138test_done