]> git.ipfire.org Git - thirdparty/git.git/blame - t/t0002-gitfile.sh
Start the 2.46 cycle
[thirdparty/git.git] / t / t0002-gitfile.sh
CommitLineData
b44ebb19
LH
1#!/bin/sh
2
3test_description='.git file
4
5Verify that plumbing commands work when .git is a file
6'
06d53148 7GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
334afbc7
JS
8export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
9
c150064d 10TEST_PASSES_SANITIZE_LEAK=true
b44ebb19
LH
11. ./test-lib.sh
12
13objpath() {
70eabce8 14 echo "$1" | sed -e 's|\(..\)|\1/|'
b44ebb19
LH
15}
16
b44ebb19
LH
17test_expect_success 'initial setup' '
18 REAL="$(pwd)/.real" &&
19 mv .git "$REAL"
20'
21
22test_expect_success 'bad setup: invalid .git file format' '
23 echo "gitdir $REAL" >.git &&
dedfdb9c 24 test_must_fail git rev-parse 2>.err &&
6789275d 25 test_grep "invalid gitfile format" .err
b44ebb19
LH
26'
27
28test_expect_success 'bad setup: invalid .git file path' '
29 echo "gitdir: $REAL.not" >.git &&
dedfdb9c 30 test_must_fail git rev-parse 2>.err &&
6789275d 31 test_grep "not a git repository" .err
b44ebb19
LH
32'
33
34test_expect_success 'final setup + check rev-parse --git-dir' '
35 echo "gitdir: $REAL" >.git &&
4bd0785d
ÆAB
36 echo "$REAL" >expect &&
37 git rev-parse --git-dir >actual &&
38 test_cmp expect actual
b44ebb19
LH
39'
40
41test_expect_success 'check hash-object' '
42 echo "foo" >bar &&
74615c2a 43 SHA=$(git hash-object -w --stdin <bar) &&
dedfdb9c 44 test_path_is_file "$REAL/objects/$(objpath $SHA)"
b44ebb19
LH
45'
46
47test_expect_success 'check cat-file' '
48 git cat-file blob $SHA >actual &&
2b14d072 49 test_cmp bar actual
b44ebb19
LH
50'
51
52test_expect_success 'check update-index' '
dedfdb9c 53 test_path_is_missing "$REAL/index" &&
b44ebb19
LH
54 rm -f "$REAL/objects/$(objpath $SHA)" &&
55 git update-index --add bar &&
dedfdb9c
JK
56 test_path_is_file "$REAL/index" &&
57 test_path_is_file "$REAL/objects/$(objpath $SHA)"
b44ebb19
LH
58'
59
60test_expect_success 'check write-tree' '
61 SHA=$(git write-tree) &&
dedfdb9c 62 test_path_is_file "$REAL/objects/$(objpath $SHA)"
b44ebb19
LH
63'
64
65test_expect_success 'check commit-tree' '
66 SHA=$(echo "commit bar" | git commit-tree $SHA) &&
dedfdb9c 67 test_path_is_file "$REAL/objects/$(objpath $SHA)"
b44ebb19
LH
68'
69
96ecf699 70test_expect_success 'check rev-list' '
cdb73ca5 71 git update-ref "HEAD" "$SHA" &&
c4d1d526
ÆAB
72 git rev-list HEAD >actual &&
73 echo $SHA >expected &&
74 test_cmp expected actual
b44ebb19
LH
75'
76
86d26f24 77test_expect_success 'setup_git_dir twice in subdir' '
d95138e6
NTND
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
31041209
NTND
94test_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 ) &&
0de267b2 103 head=$(git -C enter_repo rev-parse HEAD) &&
31041209 104 git ls-remote enter_repo >actual &&
0de267b2 105 cat >expected <<-EOF &&
106 $head HEAD
06d53148 107 $head refs/heads/main
0de267b2 108 $head refs/tags/foo
31041209
NTND
109 EOF
110 test_cmp expected actual
111'
112
0f64cc40
NTND
113test_expect_success 'enter_repo linked checkout' '
114 (
115 cd enter_repo &&
116 git worktree add ../foo refs/tags/foo
117 ) &&
0de267b2 118 head=$(git -C enter_repo rev-parse HEAD) &&
0f64cc40 119 git ls-remote foo >actual &&
0de267b2 120 cat >expected <<-EOF &&
121 $head HEAD
06d53148 122 $head refs/heads/main
0de267b2 123 $head refs/tags/foo
0f64cc40
NTND
124 EOF
125 test_cmp expected actual
126'
127
1f5fbe1f 128test_expect_success 'enter_repo strict mode' '
0de267b2 129 head=$(git -C enter_repo rev-parse HEAD) &&
1f5fbe1f 130 git ls-remote --upload-pack="git upload-pack --strict" foo/.git >actual &&
0de267b2 131 cat >expected <<-EOF &&
132 $head HEAD
06d53148 133 $head refs/heads/main
0de267b2 134 $head refs/tags/foo
1f5fbe1f
NTND
135 EOF
136 test_cmp expected actual
137'
138
b44ebb19 139test_done