3 test_description
='.git file
5 Verify that plumbing commands work when .git is a file
7 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
=main
8 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
10 TEST_PASSES_SANITIZE_LEAK
=true
14 echo "$1" |
sed -e 's|\(..\)|\1/|'
17 test_expect_success
'initial setup' '
18 REAL="$(pwd)/.real" &&
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
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
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
41 test_expect_success
'check hash-object' '
43 SHA=$(cat bar | git hash-object -w --stdin) &&
44 test_path_is_file "$REAL/objects/$(objpath $SHA)"
47 test_expect_success
'check cat-file' '
48 git cat-file blob $SHA >actual &&
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)"
60 test_expect_success
'check write-tree' '
61 SHA=$(git write-tree) &&
62 test_path_is_file "$REAL/objects/$(objpath $SHA)"
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)"
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
77 test_expect_success
'setup_git_dir twice in subdir' '
81 git config alias.lsfi ls-files &&
83 echo "gitdir: .realgit" >.git &&
90 test_cmp expected actual
94 test_expect_success
'enter_repo non-strict mode' '
95 test_create_repo enter_repo &&
101 echo "gitdir: .realgit" >.git
103 head=$(git -C enter_repo rev-parse HEAD) &&
104 git ls-remote enter_repo >actual &&
105 cat >expected <<-EOF &&
107 $head refs/heads/main
110 test_cmp expected actual
113 test_expect_success
'enter_repo linked checkout' '
116 git worktree add ../foo refs/tags/foo
118 head=$(git -C enter_repo rev-parse HEAD) &&
119 git ls-remote foo >actual &&
120 cat >expected <<-EOF &&
122 $head refs/heads/main
125 test_cmp expected actual
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 &&
133 $head refs/heads/main
136 test_cmp expected actual