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