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_i18ngrep "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_i18ngrep "not a git repository" .err
34 test_expect_success
'final setup + check rev-parse --git-dir' '
35 echo "gitdir: $REAL" >.git &&
36 test "$REAL" = "$(git rev-parse --git-dir)"
39 test_expect_success
'check hash-object' '
41 SHA=$(cat bar | git hash-object -w --stdin) &&
42 test_path_is_file "$REAL/objects/$(objpath $SHA)"
45 test_expect_success
'check cat-file' '
46 git cat-file blob $SHA >actual &&
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)"
58 test_expect_success
'check write-tree' '
59 SHA=$(git write-tree) &&
60 test_path_is_file "$REAL/objects/$(objpath $SHA)"
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)"
68 test_expect_success
'check rev-list' '
69 git update-ref "HEAD" "$SHA" &&
70 test "$SHA" = "$(git rev-list HEAD)"
73 test_expect_success
'setup_git_dir twice in subdir' '
77 git config alias.lsfi ls-files &&
79 echo "gitdir: .realgit" >.git &&
86 test_cmp expected actual
90 test_expect_success
'enter_repo non-strict mode' '
91 test_create_repo enter_repo &&
97 echo "gitdir: .realgit" >.git
99 head=$(git -C enter_repo rev-parse HEAD) &&
100 git ls-remote enter_repo >actual &&
101 cat >expected <<-EOF &&
103 $head refs/heads/main
106 test_cmp expected actual
109 test_expect_success
'enter_repo linked checkout' '
112 git worktree add ../foo refs/tags/foo
114 head=$(git -C enter_repo rev-parse HEAD) &&
115 git ls-remote foo >actual &&
116 cat >expected <<-EOF &&
118 $head refs/heads/main
121 test_cmp expected actual
124 test_expect_success
'enter_repo strict mode' '
125 head=$(git -C enter_repo rev-parse HEAD) &&
126 git ls-remote --upload-pack="git upload-pack --strict" foo/.git >actual &&
127 cat >expected <<-EOF &&
129 $head refs/heads/main
132 test_cmp expected actual