]>
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 | ' | |
7 | . ./test-lib.sh | |
8 | ||
9 | objpath() { | |
70eabce8 | 10 | echo "$1" | sed -e 's|\(..\)|\1/|' |
b44ebb19 LH |
11 | } |
12 | ||
13 | objck() { | |
14 | p=$(objpath "$1") | |
15 | if test ! -f "$REAL/objects/$p" | |
16 | then | |
17 | echo "Object not found: $REAL/objects/$p" | |
18 | false | |
19 | fi | |
20 | } | |
21 | ||
b44ebb19 LH |
22 | test_expect_success 'initial setup' ' |
23 | REAL="$(pwd)/.real" && | |
24 | mv .git "$REAL" | |
25 | ' | |
26 | ||
27 | test_expect_success 'bad setup: invalid .git file format' ' | |
28 | echo "gitdir $REAL" >.git && | |
29 | if git rev-parse 2>.err | |
30 | then | |
31 | echo "git rev-parse accepted an invalid .git file" | |
32 | false | |
33 | fi && | |
87539416 | 34 | if ! grep "Invalid gitfile format" .err |
b44ebb19 LH |
35 | then |
36 | echo "git rev-parse returned wrong error" | |
37 | false | |
38 | fi | |
39 | ' | |
40 | ||
41 | test_expect_success 'bad setup: invalid .git file path' ' | |
42 | echo "gitdir: $REAL.not" >.git && | |
43 | if git rev-parse 2>.err | |
44 | then | |
45 | echo "git rev-parse accepted an invalid .git file path" | |
46 | false | |
47 | fi && | |
87539416 | 48 | if ! grep "Not a git repository" .err |
b44ebb19 LH |
49 | then |
50 | echo "git rev-parse returned wrong error" | |
51 | false | |
52 | fi | |
53 | ' | |
54 | ||
55 | test_expect_success 'final setup + check rev-parse --git-dir' ' | |
56 | echo "gitdir: $REAL" >.git && | |
57 | test "$REAL" = "$(git rev-parse --git-dir)" | |
58 | ' | |
59 | ||
60 | test_expect_success 'check hash-object' ' | |
61 | echo "foo" >bar && | |
62 | SHA=$(cat bar | git hash-object -w --stdin) && | |
63 | objck $SHA | |
64 | ' | |
65 | ||
66 | test_expect_success 'check cat-file' ' | |
67 | git cat-file blob $SHA >actual && | |
2b14d072 | 68 | test_cmp bar actual |
b44ebb19 LH |
69 | ' |
70 | ||
71 | test_expect_success 'check update-index' ' | |
72 | if test -f "$REAL/index" | |
73 | then | |
74 | echo "Hmm, $REAL/index exists?" | |
75 | false | |
76 | fi && | |
77 | rm -f "$REAL/objects/$(objpath $SHA)" && | |
78 | git update-index --add bar && | |
79 | if ! test -f "$REAL/index" | |
80 | then | |
81 | echo "$REAL/index not found" | |
82 | false | |
83 | fi && | |
84 | objck $SHA | |
85 | ' | |
86 | ||
87 | test_expect_success 'check write-tree' ' | |
88 | SHA=$(git write-tree) && | |
89 | objck $SHA | |
90 | ' | |
91 | ||
92 | test_expect_success 'check commit-tree' ' | |
93 | SHA=$(echo "commit bar" | git commit-tree $SHA) && | |
94 | objck $SHA | |
95 | ' | |
96 | ||
97 | test_expect_success 'check rev-list' ' | |
98 | echo $SHA >"$REAL/HEAD" && | |
99 | test "$SHA" = "$(git rev-list HEAD)" | |
100 | ' | |
101 | ||
86d26f24 | 102 | test_expect_success 'setup_git_dir twice in subdir' ' |
d95138e6 NTND |
103 | git init sgd && |
104 | ( | |
105 | cd sgd && | |
106 | git config alias.lsfi ls-files && | |
107 | mv .git .realgit && | |
108 | echo "gitdir: .realgit" >.git && | |
109 | mkdir subdir && | |
110 | cd subdir && | |
111 | >foo && | |
112 | git add foo && | |
113 | git lsfi >actual && | |
114 | echo foo >expected && | |
115 | test_cmp expected actual | |
116 | ) | |
117 | ' | |
118 | ||
31041209 NTND |
119 | test_expect_success 'enter_repo non-strict mode' ' |
120 | test_create_repo enter_repo && | |
121 | ( | |
122 | cd enter_repo && | |
123 | test_tick && | |
124 | test_commit foo && | |
125 | mv .git .realgit && | |
126 | echo "gitdir: .realgit" >.git | |
127 | ) && | |
128 | git ls-remote enter_repo >actual && | |
129 | cat >expected <<-\EOF && | |
130 | 946e985ab20de757ca5b872b16d64e92ff3803a9 HEAD | |
131 | 946e985ab20de757ca5b872b16d64e92ff3803a9 refs/heads/master | |
132 | 946e985ab20de757ca5b872b16d64e92ff3803a9 refs/tags/foo | |
133 | EOF | |
134 | test_cmp expected actual | |
135 | ' | |
136 | ||
0f64cc40 NTND |
137 | test_expect_success 'enter_repo linked checkout' ' |
138 | ( | |
139 | cd enter_repo && | |
140 | git worktree add ../foo refs/tags/foo | |
141 | ) && | |
142 | git ls-remote foo >actual && | |
143 | cat >expected <<-\EOF && | |
144 | 946e985ab20de757ca5b872b16d64e92ff3803a9 HEAD | |
145 | 946e985ab20de757ca5b872b16d64e92ff3803a9 refs/heads/master | |
146 | 946e985ab20de757ca5b872b16d64e92ff3803a9 refs/tags/foo | |
147 | EOF | |
148 | test_cmp expected actual | |
149 | ' | |
150 | ||
1f5fbe1f NTND |
151 | test_expect_success 'enter_repo strict mode' ' |
152 | git ls-remote --upload-pack="git upload-pack --strict" foo/.git >actual && | |
153 | cat >expected <<-\EOF && | |
154 | 946e985ab20de757ca5b872b16d64e92ff3803a9 HEAD | |
155 | 946e985ab20de757ca5b872b16d64e92ff3803a9 refs/heads/master | |
156 | 946e985ab20de757ca5b872b16d64e92ff3803a9 refs/tags/foo | |
157 | EOF | |
158 | test_cmp expected actual | |
159 | ' | |
160 | ||
b44ebb19 | 161 | test_done |