advice: omit trailing whitespace
[git.git] / t / t0002-gitfile.sh
blobbf3bf604abe3470f19cc5a10e5c88c905cb28329
1 #!/bin/sh
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
11 . ./test-lib.sh
13 objpath() {
14 echo "$1" | sed -e 's|\(..\)|\1/|'
17 test_expect_success 'initial setup' '
18 REAL="$(pwd)/.real" &&
19 mv .git "$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' '
42 echo "foo" >bar &&
43 SHA=$(git hash-object -w --stdin <bar) &&
44 test_path_is_file "$REAL/objects/$(objpath $SHA)"
47 test_expect_success 'check cat-file' '
48 git cat-file blob $SHA >actual &&
49 test_cmp bar 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' '
78 git init sgd &&
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
94 test_expect_success 'enter_repo non-strict mode' '
95 test_create_repo enter_repo &&
97 cd enter_repo &&
98 test_tick &&
99 test_commit foo &&
100 mv .git .realgit &&
101 echo "gitdir: .realgit" >.git
102 ) &&
103 head=$(git -C enter_repo rev-parse HEAD) &&
104 git ls-remote enter_repo >actual &&
105 cat >expected <<-EOF &&
106 $head HEAD
107 $head refs/heads/main
108 $head refs/tags/foo
110 test_cmp expected actual
113 test_expect_success 'enter_repo linked checkout' '
115 cd enter_repo &&
116 git worktree add ../foo refs/tags/foo
117 ) &&
118 head=$(git -C enter_repo rev-parse HEAD) &&
119 git ls-remote foo >actual &&
120 cat >expected <<-EOF &&
121 $head HEAD
122 $head refs/heads/main
123 $head refs/tags/foo
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 &&
132 $head HEAD
133 $head refs/heads/main
134 $head refs/tags/foo
136 test_cmp expected actual
139 test_done