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