]> git.ipfire.org Git - thirdparty/git.git/blame - t/t0002-gitfile.sh
leak tests: mark all trace2 tests as passing with SANITIZE=leak
[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 &&
d4053966 25 test_i18ngrep "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 &&
d4053966 31 test_i18ngrep "not a git repository" .err
b44ebb19
LH
32'
33
34test_expect_success 'final setup + check rev-parse --git-dir' '
35 echo "gitdir: $REAL" >.git &&
36 test "$REAL" = "$(git rev-parse --git-dir)"
37'
38
39test_expect_success 'check hash-object' '
40 echo "foo" >bar &&
41 SHA=$(cat bar | git hash-object -w --stdin) &&
dedfdb9c 42 test_path_is_file "$REAL/objects/$(objpath $SHA)"
b44ebb19
LH
43'
44
45test_expect_success 'check cat-file' '
46 git cat-file blob $SHA >actual &&
2b14d072 47 test_cmp bar actual
b44ebb19
LH
48'
49
50test_expect_success 'check update-index' '
dedfdb9c 51 test_path_is_missing "$REAL/index" &&
b44ebb19
LH
52 rm -f "$REAL/objects/$(objpath $SHA)" &&
53 git update-index --add bar &&
dedfdb9c
JK
54 test_path_is_file "$REAL/index" &&
55 test_path_is_file "$REAL/objects/$(objpath $SHA)"
b44ebb19
LH
56'
57
58test_expect_success 'check write-tree' '
59 SHA=$(git write-tree) &&
dedfdb9c 60 test_path_is_file "$REAL/objects/$(objpath $SHA)"
b44ebb19
LH
61'
62
63test_expect_success 'check commit-tree' '
64 SHA=$(echo "commit bar" | git commit-tree $SHA) &&
dedfdb9c 65 test_path_is_file "$REAL/objects/$(objpath $SHA)"
b44ebb19
LH
66'
67
68test_expect_success 'check rev-list' '
cdb73ca5 69 git update-ref "HEAD" "$SHA" &&
b44ebb19
LH
70 test "$SHA" = "$(git rev-list HEAD)"
71'
72
86d26f24 73test_expect_success 'setup_git_dir twice in subdir' '
d95138e6
NTND
74 git init sgd &&
75 (
76 cd sgd &&
77 git config alias.lsfi ls-files &&
78 mv .git .realgit &&
79 echo "gitdir: .realgit" >.git &&
80 mkdir subdir &&
81 cd subdir &&
82 >foo &&
83 git add foo &&
84 git lsfi >actual &&
85 echo foo >expected &&
86 test_cmp expected actual
87 )
88'
89
31041209
NTND
90test_expect_success 'enter_repo non-strict mode' '
91 test_create_repo enter_repo &&
92 (
93 cd enter_repo &&
94 test_tick &&
95 test_commit foo &&
96 mv .git .realgit &&
97 echo "gitdir: .realgit" >.git
98 ) &&
0de267b2 99 head=$(git -C enter_repo rev-parse HEAD) &&
31041209 100 git ls-remote enter_repo >actual &&
0de267b2 101 cat >expected <<-EOF &&
102 $head HEAD
06d53148 103 $head refs/heads/main
0de267b2 104 $head refs/tags/foo
31041209
NTND
105 EOF
106 test_cmp expected actual
107'
108
0f64cc40
NTND
109test_expect_success 'enter_repo linked checkout' '
110 (
111 cd enter_repo &&
112 git worktree add ../foo refs/tags/foo
113 ) &&
0de267b2 114 head=$(git -C enter_repo rev-parse HEAD) &&
0f64cc40 115 git ls-remote foo >actual &&
0de267b2 116 cat >expected <<-EOF &&
117 $head HEAD
06d53148 118 $head refs/heads/main
0de267b2 119 $head refs/tags/foo
0f64cc40
NTND
120 EOF
121 test_cmp expected actual
122'
123
1f5fbe1f 124test_expect_success 'enter_repo strict mode' '
0de267b2 125 head=$(git -C enter_repo rev-parse HEAD) &&
1f5fbe1f 126 git ls-remote --upload-pack="git upload-pack --strict" foo/.git >actual &&
0de267b2 127 cat >expected <<-EOF &&
128 $head HEAD
06d53148 129 $head refs/heads/main
0de267b2 130 $head refs/tags/foo
1f5fbe1f
NTND
131 EOF
132 test_cmp expected actual
133'
134
b44ebb19 135test_done