]>
Commit | Line | Data |
---|---|---|
b44ebb19 LH |
1 | #!/bin/sh |
2 | ||
3 | test_description='.git file | |
4 | ||
5 | Verify that plumbing commands work when .git is a file | |
6 | ' | |
06d53148 | 7 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main |
334afbc7 JS |
8 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME |
9 | ||
b44ebb19 LH |
10 | . ./test-lib.sh |
11 | ||
12 | objpath() { | |
70eabce8 | 13 | echo "$1" | sed -e 's|\(..\)|\1/|' |
b44ebb19 LH |
14 | } |
15 | ||
b44ebb19 LH |
16 | test_expect_success 'initial setup' ' |
17 | REAL="$(pwd)/.real" && | |
18 | mv .git "$REAL" | |
19 | ' | |
20 | ||
21 | test_expect_success 'bad setup: invalid .git file format' ' | |
22 | echo "gitdir $REAL" >.git && | |
dedfdb9c | 23 | test_must_fail git rev-parse 2>.err && |
d4053966 | 24 | test_i18ngrep "invalid gitfile format" .err |
b44ebb19 LH |
25 | ' |
26 | ||
27 | test_expect_success 'bad setup: invalid .git file path' ' | |
28 | echo "gitdir: $REAL.not" >.git && | |
dedfdb9c | 29 | test_must_fail git rev-parse 2>.err && |
d4053966 | 30 | test_i18ngrep "not a git repository" .err |
b44ebb19 LH |
31 | ' |
32 | ||
33 | test_expect_success 'final setup + check rev-parse --git-dir' ' | |
34 | echo "gitdir: $REAL" >.git && | |
35 | test "$REAL" = "$(git rev-parse --git-dir)" | |
36 | ' | |
37 | ||
38 | test_expect_success 'check hash-object' ' | |
39 | echo "foo" >bar && | |
40 | SHA=$(cat bar | git hash-object -w --stdin) && | |
dedfdb9c | 41 | test_path_is_file "$REAL/objects/$(objpath $SHA)" |
b44ebb19 LH |
42 | ' |
43 | ||
44 | test_expect_success 'check cat-file' ' | |
45 | git cat-file blob $SHA >actual && | |
2b14d072 | 46 | test_cmp bar actual |
b44ebb19 LH |
47 | ' |
48 | ||
49 | test_expect_success 'check update-index' ' | |
dedfdb9c | 50 | test_path_is_missing "$REAL/index" && |
b44ebb19 LH |
51 | rm -f "$REAL/objects/$(objpath $SHA)" && |
52 | git update-index --add bar && | |
dedfdb9c JK |
53 | test_path_is_file "$REAL/index" && |
54 | test_path_is_file "$REAL/objects/$(objpath $SHA)" | |
b44ebb19 LH |
55 | ' |
56 | ||
57 | test_expect_success 'check write-tree' ' | |
58 | SHA=$(git write-tree) && | |
dedfdb9c | 59 | test_path_is_file "$REAL/objects/$(objpath $SHA)" |
b44ebb19 LH |
60 | ' |
61 | ||
62 | test_expect_success 'check commit-tree' ' | |
63 | SHA=$(echo "commit bar" | git commit-tree $SHA) && | |
dedfdb9c | 64 | test_path_is_file "$REAL/objects/$(objpath $SHA)" |
b44ebb19 LH |
65 | ' |
66 | ||
67 | test_expect_success 'check rev-list' ' | |
cdb73ca5 | 68 | git update-ref "HEAD" "$SHA" && |
b44ebb19 LH |
69 | test "$SHA" = "$(git rev-list HEAD)" |
70 | ' | |
71 | ||
86d26f24 | 72 | test_expect_success 'setup_git_dir twice in subdir' ' |
d95138e6 NTND |
73 | git init sgd && |
74 | ( | |
75 | cd sgd && | |
76 | git config alias.lsfi ls-files && | |
77 | mv .git .realgit && | |
78 | echo "gitdir: .realgit" >.git && | |
79 | mkdir subdir && | |
80 | cd subdir && | |
81 | >foo && | |
82 | git add foo && | |
83 | git lsfi >actual && | |
84 | echo foo >expected && | |
85 | test_cmp expected actual | |
86 | ) | |
87 | ' | |
88 | ||
31041209 NTND |
89 | test_expect_success 'enter_repo non-strict mode' ' |
90 | test_create_repo enter_repo && | |
91 | ( | |
92 | cd enter_repo && | |
93 | test_tick && | |
94 | test_commit foo && | |
95 | mv .git .realgit && | |
96 | echo "gitdir: .realgit" >.git | |
97 | ) && | |
0de267b2 | 98 | head=$(git -C enter_repo rev-parse HEAD) && |
31041209 | 99 | git ls-remote enter_repo >actual && |
0de267b2 | 100 | cat >expected <<-EOF && |
101 | $head HEAD | |
06d53148 | 102 | $head refs/heads/main |
0de267b2 | 103 | $head refs/tags/foo |
31041209 NTND |
104 | EOF |
105 | test_cmp expected actual | |
106 | ' | |
107 | ||
0f64cc40 NTND |
108 | test_expect_success 'enter_repo linked checkout' ' |
109 | ( | |
110 | cd enter_repo && | |
111 | git worktree add ../foo refs/tags/foo | |
112 | ) && | |
0de267b2 | 113 | head=$(git -C enter_repo rev-parse HEAD) && |
0f64cc40 | 114 | git ls-remote foo >actual && |
0de267b2 | 115 | cat >expected <<-EOF && |
116 | $head HEAD | |
06d53148 | 117 | $head refs/heads/main |
0de267b2 | 118 | $head refs/tags/foo |
0f64cc40 NTND |
119 | EOF |
120 | test_cmp expected actual | |
121 | ' | |
122 | ||
1f5fbe1f | 123 | test_expect_success 'enter_repo strict mode' ' |
0de267b2 | 124 | head=$(git -C enter_repo rev-parse HEAD) && |
1f5fbe1f | 125 | git ls-remote --upload-pack="git upload-pack --strict" foo/.git >actual && |
0de267b2 | 126 | cat >expected <<-EOF && |
127 | $head HEAD | |
06d53148 | 128 | $head refs/heads/main |
0de267b2 | 129 | $head refs/tags/foo |
1f5fbe1f NTND |
130 | EOF |
131 | test_cmp expected actual | |
132 | ' | |
133 | ||
b44ebb19 | 134 | test_done |