Debian Codegraph @

t/t-config.sh

raw symbols SCIP
1 #!/usr/bin/env bash
2
3 . "$(dirname "$0")/testlib.sh"
4
5 begin_test "default config"
6 (
7 set -e
8 reponame="default-config"
9 mkdir $reponame
10 cd $reponame
11 git init
12 git remote add origin "$GITSERVER/$reponame"
13 git lfs env | tee env.log
14 grep "Endpoint=$GITSERVER/$reponame.git/info/lfs (auth=none)" env.log
15
16 git config --file=.gitconfig lfs.url http://gitconfig-file-ignored
17 git config --file=.lfsconfig lfs.url http://lfsconfig-file
18 git config --file=.lfsconfig lfs.http://lfsconfig-file.access lfsconfig
19 git lfs env | tee env.log
20 grep "Endpoint=http://lfsconfig-file (auth=lfsconfig)" env.log
21
22 git config --file=.lfsconfig --unset lfs.url
23 git config --file=.lfsconfig --unset lfs.http://lfsconfig-file.access
24
25 # new endpoint url from local git config
26 # access setting no longer applied
27 git config lfs.url http://local-lfsconfig
28 git lfs env | tee env.log
29 grep "Endpoint=http://local-lfsconfig (auth=none)" env.log
30
31 # add the access setting to lfsconfig
32 git config --file=.lfsconfig lfs.http://local-lfsconfig.access lfsconfig
33 git lfs env | tee env.log
34 grep "Endpoint=http://local-lfsconfig (auth=lfsconfig)" env.log
35
36 git config --file=.lfsconfig --unset lfs.http://local-lfsconfig.access
37
38 # add the access setting to git config
39 git config lfs.http://local-lfsconfig.access gitconfig
40 git lfs env | tee env.log
41 grep "Endpoint=http://local-lfsconfig (auth=gitconfig)" env.log
42 )
43 end_test
44
45 begin_test "config reads from repository"
46 (
47 set -e
48 reponame="repository-config"
49 setup_remote_repo "$reponame"
50 mkdir $reponame
51 cd $reponame
52 git init
53 git remote add origin "$GITSERVER/$reponame"
54 git lfs env | tee env.log
55 grep "Endpoint=$GITSERVER/$reponame.git/info/lfs (auth=none)" env.log
56
57 git config --file=.lfsconfig lfs.url http://lfsconfig-file
58 git config --file=.lfsconfig lfs.http://lfsconfig-file.access lfsconfig
59 git add .lfsconfig
60 git commit -m 'Add file'
61 git push origin HEAD
62
63 git checkout -b side
64 git config --file=.lfsconfig lfs.url http://lfsconfig-file-side
65 git config --file=.lfsconfig lfs.http://lfsconfig-file-side.access lfsconfig
66 git add .lfsconfig
67 git commit -m 'Add file for side'
68 git push origin HEAD
69
70 mkdir "../$reponame-2"
71 cd "../$reponame-2"
72 git init
73 git remote add origin "$GITSERVER/$reponame"
74
75 git lfs env | tee env.log
76 grep "Endpoint=$GITSERVER/$reponame.git/info/lfs (auth=none)" env.log
77
78 git fetch origin
79 git symbolic-ref HEAD refs/remotes/origin/side
80 git show "HEAD:.lfsconfig"
81 git lfs env | tee env.log
82 grep "Endpoint=http://lfsconfig-file-side (auth=lfsconfig)" env.log
83
84 git read-tree refs/remotes/origin/main
85 git lfs env | tee env.log
86 grep "Endpoint=http://lfsconfig-file (auth=lfsconfig)" env.log
87 )
88 end_test
89
90 begin_test "can read LFS file with name before .lfsconfig"
91 (
92 set -e
93 reponame="early-file-config"
94 setup_remote_repo "$reponame"
95 mkdir $reponame
96 cd $reponame
97 git init
98 git remote add origin "$GITSERVER/$reponame"
99
100 git lfs track "*.bin"
101 git config --file=.lfsconfig lfs.url "$GITSERVER/$reponame.git/info/lfs"
102
103 echo "abc" > .bin
104 echo "def" > a.bin
105
106 git add .
107 git commit -m "Add files"
108 git push origin HEAD
109 rm -fr .git/lfs/objects
110
111 cd ..
112 git clone "$reponame" "$reponame-2"
113 cd "$reponame-2"
114 grep abc .bin
115 grep def a.bin
116 )
117 end_test
118
119 begin_test "extension config"
120 (
121 set -e
122
123 git config --global lfs.extension.env-test.clean "env-test-clean"
124 git config --global lfs.extension.env-test.smudge "env-test-smudge"
125 git config --global lfs.extension.env-test.priority 0
126
127 reponame="extension-config"
128 mkdir $reponame
129 cd $reponame
130 git init
131
132 expected0="Extension: env-test
133 clean = env-test-clean
134 smudge = env-test-smudge
135 priority = 0"
136
137 [ "$expected0" = "$(git lfs ext)" ]
138
139 # any git config takes precedence over .lfsconfig
140 git config --global --unset lfs.extension.env-test.priority
141
142 git config --file=.lfsconfig lfs.extension.env-test.clean "file-env-test-clean"
143 git config --file=.lfsconfig lfs.extension.env-test.smudge "file-env-test-smudge"
144 git config --file=.lfsconfig lfs.extension.env-test.priority 1
145 cat .lfsconfig
146 expected1="Extension: env-test
147 clean = env-test-clean
148 smudge = env-test-smudge
149 priority = 1"
150
151 [ "$expected1" = "$(GIT_TRACE=5 git lfs ext)" ]
152
153 git config lfs.extension.env-test.clean "local-env-test-clean"
154 git config lfs.extension.env-test.smudge "local-env-test-smudge"
155 git config lfs.extension.env-test.priority 2
156 expected2="Extension: env-test
157 clean = local-env-test-clean
158 smudge = local-env-test-smudge
159 priority = 2"
160
161 [ "$expected2" = "$(git lfs ext)" ]
162 )
163 end_test
164
165 begin_test "url alias config"
166 (
167 set -e
168
169 mkdir url-alias
170 cd url-alias
171
172 git init
173
174 # When more than one insteadOf strings match a given URL, the longest match is used.
175 git config url."http://wrong-url/".insteadOf alias
176 git config url."http://actual-url/".insteadOf alias:
177 git config lfs.url alias:rest
178 git lfs env | tee env.log
179 grep "Endpoint=http://actual-url/rest (auth=none)" env.log
180 )
181 end_test
182
183 begin_test "ambiguous url alias"
184 (
185 set -e
186
187 mkdir url-alias-ambiguous
188 cd url-alias-ambiguous
189
190 git init
191
192 git config url."http://actual-url/".insteadOf alias:
193 git config url."http://dupe-url".insteadOf alias:
194 git config lfs.url alias:rest
195 git config -l | grep url
196
197 git lfs env 2>&1 | tee env2.log
198 grep "warning: Multiple 'url.*.insteadof'" env2.log
199 )
200 end_test
201
202 begin_test "multiple config"
203 (
204 set -e
205
206 mkdir url-alias-multiple
207 cd url-alias-multiple
208
209 git init
210
211 # When more than one insteadOf strings match a given URL, the longest match is used.
212 git config url."http://wrong-url/".insteadOf alias
213 git config url."http://actual-url/".insteadOf alias:
214 git config --add url."http://actual-url/".insteadOf alias2:
215 git config lfs.url alias:rest
216 git lfs env | tee env.log
217 grep "Endpoint=http://actual-url/rest (auth=none)" env.log
218
219 git config lfs.url alias2:rest
220 git lfs env | tee env.log
221 grep "Endpoint=http://actual-url/rest (auth=none)" env.log
222 )
223 end_test
224
225
226 begin_test "url alias must be prefix"
227 (
228 set -e
229
230 mkdir url-alias-bad
231 cd url-alias-bad
232
233 git init
234
235 git config url."http://actual-url/".insteadOf alias:
236 git config lfs.url badalias:rest
237 git lfs env | tee env.log
238 grep "SSH=badalias:rest" env.log
239 )
240 end_test
241
242 begin_test "config: ignoring unsafe lfsconfig keys"
243 (
244 set -e
245
246 reponame="config-unsafe-lfsconfig-keys"
247 git init "$reponame"
248 cd "$reponame"
249
250 # Insert an 'unsafe' key into this repository's '.lfsconfig'.
251 git config --file=.lfsconfig core.askpass unsafe
252
253 git lfs env 2>&1 | tee status.log
254
255 grep "warning: These unsafe '.lfsconfig' keys were ignored:" status.log
256 grep " core.askpass" status.log
257 )
258 end_test
259
260 begin_test "config respects include.* directives when GIT_CONFIG is set"
261 (
262 set -e
263
264 mkdir include-directives
265 cd include-directives
266
267 git init
268
269 git config lfs.url "http://some-url/rest"
270 GIT_CONFIG="$(pwd)/.git/config" git lfs env | tee env.log
271 grep "Endpoint=http://some-url/rest (auth=none)" env.log
272
273 git config --file ./.git/b.config url."http://other-url/".insteadOf "http://some-url/"
274 git config include.path "$(pwd)/.git/b.config"
275 GIT_CONFIG="$(pwd)/.git/config" git lfs env | tee env.log
276 grep "Endpoint=http://other-url/rest (auth=none)" env.log
277 )
278 end_test