Debian Codegraph @

t/t-update.sh

raw symbols SCIP
1 #!/usr/bin/envscip-shell filesystem . . `/usr/bin/env`. bash
2
3 . "$(dirnamescip-shell system . . dirname. "$0")/testlib.sh"
4
5 begin_test "update"
6 (
7 set -e
8
9 pre_push_hook="#!/bin/sh
10 command -v git-lfs >/dev/null 2>&1 || { printf >&2 \"\\n%s\\n\\n\" \"This repository is configured for Git LFS but 'git-lfs' was not found on your path. If you no longer wish to use Git LFS, remove this hook by deleting the 'pre-push' file in the hooks directory (set by 'core.hookspath'; usually '.git/hooks').\"; exit 2; }
11 git lfs pre-push \"\$@\""
12
13 post_checkout_hook="#!/bin/sh
14 command -v git-lfs >/dev/null 2>&1 || { printf >&2 \"\\n%s\\n\\n\" \"This repository is configured for Git LFS but 'git-lfs' was not found on your path. If you no longer wish to use Git LFS, remove this hook by deleting the 'post-checkout' file in the hooks directory (set by 'core.hookspath'; usually '.git/hooks').\"; exit 2; }
15 git lfs post-checkout \"\$@\""
16
17 post_commit_hook="#!/bin/sh
18 command -v git-lfs >/dev/null 2>&1 || { printf >&2 \"\\n%s\\n\\n\" \"This repository is configured for Git LFS but 'git-lfs' was not found on your path. If you no longer wish to use Git LFS, remove this hook by deleting the 'post-commit' file in the hooks directory (set by 'core.hookspath'; usually '.git/hooks').\"; exit 2; }
19 git lfs post-commit \"\$@\""
20
21 post_merge_hook="#!/bin/sh
22 command -v git-lfs >/dev/null 2>&1 || { printf >&2 \"\\n%s\\n\\n\" \"This repository is configured for Git LFS but 'git-lfs' was not found on your path. If you no longer wish to use Git LFS, remove this hook by deleting the 'post-merge' file in the hooks directory (set by 'core.hookspath'; usually '.git/hooks').\"; exit 2; }
23 git lfs post-merge \"\$@\""
24
25 mkdirscip-shell system . . mkdir. without-pre-push
26 cd without-pre-push
27 gitscip-shell system . . git. init
28
29 [scip-shell system . . `[`. "Updated Git hooks." = "$(gitscip-shell system . . git. lfs update)" ]
30 [scip-shell system . . `[`. "$pre_push_hook" = "$(catscip-shell system . . cat. .git/hooks/pre-push)" ]
31 [scip-shell system . . `[`. "$post_checkout_hook" = "$(catscip-shell system . . cat. .git/hooks/post-checkout)" ]
32 [scip-shell system . . `[`. "$post_commit_hook" = "$(catscip-shell system . . cat. .git/hooks/post-commit)" ]
33 [scip-shell system . . `[`. "$post_merge_hook" = "$(catscip-shell system . . cat. .git/hooks/post-merge)" ]
34
35 # run it again
36 [scip-shell system . . `[`. "Updated Git hooks." = "$(gitscip-shell system . . git. lfs update)" ]
37 [scip-shell system . . `[`. "$pre_push_hook" = "$(catscip-shell system . . cat. .git/hooks/pre-push)" ]
38 [scip-shell system . . `[`. "$post_checkout_hook" = "$(catscip-shell system . . cat. .git/hooks/post-checkout)" ]
39 [scip-shell system . . `[`. "$post_commit_hook" = "$(catscip-shell system . . cat. .git/hooks/post-commit)" ]
40 [scip-shell system . . `[`. "$post_merge_hook" = "$(catscip-shell system . . cat. .git/hooks/post-merge)" ]
41
42 # replace old hook 1
43 echoscip-shell system . . echo. "#!/bin/sh
44 git lfs push --stdin \$*" > .git/hooks/pre-push
45 [scip-shell system . . `[`. "Updated Git hooks." = "$(gitscip-shell system . . git. lfs update)" ]
46 [scip-shell system . . `[`. "$pre_push_hook" = "$(catscip-shell system . . cat. .git/hooks/pre-push)" ]
47
48 # replace old hook 2
49 echoscip-shell system . . echo. "#!/bin/sh
50 git lfs push --stdin \"\$@\"" > .git/hooks/pre-push
51 [scip-shell system . . `[`. "Updated Git hooks." = "$(gitscip-shell system . . git. lfs update)" ]
52 [scip-shell system . . `[`. "$pre_push_hook" = "$(catscip-shell system . . cat. .git/hooks/pre-push)" ]
53
54 # replace old hook 3
55 echoscip-shell system . . echo. "#!/bin/sh
56 git lfs pre-push \"\$@\"" > .git/hooks/pre-push
57 [scip-shell system . . `[`. "Updated Git hooks." = "$(gitscip-shell system . . git. lfs update)" ]
58 [scip-shell system . . `[`. "$pre_push_hook" = "$(catscip-shell system . . cat. .git/hooks/pre-push)" ]
59
60 # replace blank hook
61 rmscip-shell system . . rm. .git/hooks/pre-push
62 touchscip-shell system . . touch. .git/hooks/pre-push
63 touchscip-shell system . . touch. .git/hooks/post-checkout
64 touchscip-shell system . . touch. .git/hooks/post-merge
65 [scip-shell system . . `[`. "Updated Git hooks." = "$(gitscip-shell system . . git. lfs update)" ]
66 [scip-shell system . . `[`. "$pre_push_hook" = "$(catscip-shell system . . cat. .git/hooks/pre-push)" ]
67 [scip-shell system . . `[`. "$post_checkout_hook" = "$(catscip-shell system . . cat. .git/hooks/post-checkout)" ]
68 [scip-shell system . . `[`. "$post_commit_hook" = "$(catscip-shell system . . cat. .git/hooks/post-commit)" ]
69 [scip-shell system . . `[`. "$post_merge_hook" = "$(catscip-shell system . . cat. .git/hooks/post-merge)" ]
70
71 # replace old hook 4
72 echoscip-shell system . . echo. "#!/bin/sh
73 command -v git-lfs >/dev/null 2>&1 || { echo >&2 \"\\nThis repository has been set up with Git LFS but Git LFS is not installed.\\n\"; exit 0; }
74 git lfs pre-push \"\$@\"" > .git/hooks/pre-push
75 [scip-shell system . . `[`. "Updated Git hooks." = "$(gitscip-shell system . . git. lfs update)" ]
76 [scip-shell system . . `[`. "$pre_push_hook" = "$(catscip-shell system . . cat. .git/hooks/pre-push)" ]
77
78 # replace old hook 5
79 echoscip-shell system . . echo. "#!/bin/sh
80 command -v git-lfs >/dev/null 2>&1 || { echo >&2 \"\\nThis repository has been set up with Git LFS but Git LFS is not installed.\\n\"; exit 2; }
81 git lfs pre-push \"\$@\"" > .git/hooks/pre-push
82 [scip-shell system . . `[`. "Updated Git hooks." = "$(gitscip-shell system . . git. lfs update)" ]
83 [scip-shell system . . `[`. "$pre_push_hook" = "$(catscip-shell system . . cat. .git/hooks/pre-push)" ]
84
85 # replace old hook 6
86 echoscip-shell system . . echo. "#!/bin/sh
87 command -v git-lfs >/dev/null 2>&1 || { echo >&2 \"\\nThis repository is configured for Git LFS but 'git-lfs' was not found on your path. If you no longer wish to use Git LFS, remove this hook by deleting '.git/hooks/pre-push'.\\n\"; exit 2; }
88 git lfs pre-push \"\$@\"" > .git/hooks/pre-push
89 [scip-shell system . . `[`. "Updated Git hooks." = "$(gitscip-shell system . . git. lfs update)" ]
90 [scip-shell system . . `[`. "$pre_push_hook" = "$(catscip-shell system . . cat. .git/hooks/pre-push)" ]
91
92 # replace old hook 7
93 echoscip-shell system . . echo. "#!/bin/sh
94 command -v git-lfs >/dev/null 2>&1 || { echo >&2 \"\\nThis repository is configured for Git LFS but 'git-lfs' was not found on your path. If you no longer wish to use Git LFS, remove this hook by deleting the 'pre-push' file in the hooks directory (set by 'core.hookspath'; usually '.git/hooks').\\n\"; exit 2; }
95 git lfs pre-push \"\$@\"" > .git/hooks/pre-push
96 [scip-shell system . . `[`. "Updated Git hooks." = "$(gitscip-shell system . . git. lfs update)" ]
97 [scip-shell system . . `[`. "$pre_push_hook" = "$(catscip-shell system . . cat. .git/hooks/pre-push)" ]
98
99 # don't replace unexpected hook
100 echoscip-shell system . . echo. "test" > .git/hooks/pre-push
101 echoscip-shell system . . echo. "test" > .git/hooks/post-checkout
102 echoscip-shell system . . echo. "test" > .git/hooks/post-commit
103 echoscip-shell system . . echo. "test" > .git/hooks/post-merge
104 expected="Hook already exists: pre-push
105
106 test
107
108 To resolve this, either:
109 1: run \`git lfs update --manual\` for instructions on how to merge hooks.
110 2: run \`git lfs update --force\` to overwrite your hook."
111
112 [scip-shell system . . `[`. "$expected" = "$(gitscip-shell system . . git. lfs update 2>&1)" ]
113 [scip-shell system . . `[`. "test" = "$(catscip-shell system . . cat. .git/hooks/pre-push)" ]
114 [scip-shell system . . `[`. "test" = "$(catscip-shell system . . cat. .git/hooks/post-checkout)" ]
115 [scip-shell system . . `[`. "test" = "$(catscip-shell system . . cat. .git/hooks/post-commit)" ]
116 [scip-shell system . . `[`. "test" = "$(catscip-shell system . . cat. .git/hooks/post-merge)" ]
117
118 # Make sure returns non-zero
119 set +e
120 gitscip-shell system . . git. lfs update
121 if [scip-shell system . . `[`. $? -eq 0 ]
122 then
123 exit 1
124 fi
125 set -e
126
127 # test manual steps
128 expected="Add the following to '.git/hooks/pre-push':
129
130 #!/bin/sh
131 command -v git-lfs >/dev/null 2>&1 || { printf >&2 \"\n%s\n\n\" \"This repository is configured for Git LFS but 'git-lfs' was not found on your path. If you no longer wish to use Git LFS, remove this hook by deleting the 'pre-push' file in the hooks directory (set by 'core.hookspath'; usually '.git/hooks').\"; exit 2; }
132 git lfs pre-push \"\$@\"
133
134 Add the following to '.git/hooks/post-checkout':
135
136 #!/bin/sh
137 command -v git-lfs >/dev/null 2>&1 || { printf >&2 \"\n%s\n\n\" \"This repository is configured for Git LFS but 'git-lfs' was not found on your path. If you no longer wish to use Git LFS, remove this hook by deleting the 'post-checkout' file in the hooks directory (set by 'core.hookspath'; usually '.git/hooks').\"; exit 2; }
138 git lfs post-checkout \"\$@\"
139
140 Add the following to '.git/hooks/post-commit':
141
142 #!/bin/sh
143 command -v git-lfs >/dev/null 2>&1 || { printf >&2 \"\n%s\n\n\" \"This repository is configured for Git LFS but 'git-lfs' was not found on your path. If you no longer wish to use Git LFS, remove this hook by deleting the 'post-commit' file in the hooks directory (set by 'core.hookspath'; usually '.git/hooks').\"; exit 2; }
144 git lfs post-commit \"\$@\"
145
146 Add the following to '.git/hooks/post-merge':
147
148 #!/bin/sh
149 command -v git-lfs >/dev/null 2>&1 || { printf >&2 \"\n%s\n\n\" \"This repository is configured for Git LFS but 'git-lfs' was not found on your path. If you no longer wish to use Git LFS, remove this hook by deleting the 'post-merge' file in the hooks directory (set by 'core.hookspath'; usually '.git/hooks').\"; exit 2; }
150 git lfs post-merge \"\$@\""
151
152 [scip-shell system . . `[`. "$expected" = "$(gitscip-shell system . . git. lfs update --manual 2>&1)" ]
153 [scip-shell system . . `[`. "test" = "$(catscip-shell system . . cat. .git/hooks/pre-push)" ]
154 [scip-shell system . . `[`. "test" = "$(catscip-shell system . . cat. .git/hooks/post-checkout)" ]
155 [scip-shell system . . `[`. "test" = "$(catscip-shell system . . cat. .git/hooks/post-commit)" ]
156 [scip-shell system . . `[`. "test" = "$(catscip-shell system . . cat. .git/hooks/post-merge)" ]
157
158 # force replace unexpected hook
159 [scip-shell system . . `[`. "Updated Git hooks." = "$(gitscip-shell system . . git. lfs update --force)" ]
160 [scip-shell system . . `[`. "$pre_push_hook" = "$(catscip-shell system . . cat. .git/hooks/pre-push)" ]
161 [scip-shell system . . `[`. "$post_checkout_hook" = "$(catscip-shell system . . cat. .git/hooks/post-checkout)" ]
162 [scip-shell system . . `[`. "$post_commit_hook" = "$(catscip-shell system . . cat. .git/hooks/post-commit)" ]
163 [scip-shell system . . `[`. "$post_merge_hook" = "$(catscip-shell system . . cat. .git/hooks/post-merge)" ]
164
165 # test manual steps with core.hookspath
166 gitversion=$(gitscip-shell system . . git. version | cutscip-shell system . . cut. -d" " -f3)
167 set +e
168 compare_version "$gitversion" 2.9.0
169 result=$?
170 set -e
171 if [scip-shell system . . `[`. "$result" -ne "$VERSION_LOWER" ]
172 then
173 mkdirscip-shell system . . mkdir. hooks
174 rmscip-shell system . . rm. -fr .git/hooks
175 gitscip-shell system . . git. config core.hookspath hooks
176 echoscip-shell system . . echo. "test" > hooks/pre-push
177 echoscip-shell system . . echo. "test" > hooks/post-checkout
178 echoscip-shell system . . echo. "test" > hooks/post-commit
179 echoscip-shell system . . echo. "test" > hooks/post-merge
180
181 expected="Add the following to 'hooks/pre-push':
182
183 #!/bin/sh
184 command -v git-lfs >/dev/null 2>&1 || { printf >&2 \"\n%s\n\n\" \"This repository is configured for Git LFS but 'git-lfs' was not found on your path. If you no longer wish to use Git LFS, remove this hook by deleting the 'pre-push' file in the hooks directory (set by 'core.hookspath'; usually '.git/hooks').\"; exit 2; }
185 git lfs pre-push \"\$@\"
186
187 Add the following to 'hooks/post-checkout':
188
189 #!/bin/sh
190 command -v git-lfs >/dev/null 2>&1 || { printf >&2 \"\n%s\n\n\" \"This repository is configured for Git LFS but 'git-lfs' was not found on your path. If you no longer wish to use Git LFS, remove this hook by deleting the 'post-checkout' file in the hooks directory (set by 'core.hookspath'; usually '.git/hooks').\"; exit 2; }
191 git lfs post-checkout \"\$@\"
192
193 Add the following to 'hooks/post-commit':
194
195 #!/bin/sh
196 command -v git-lfs >/dev/null 2>&1 || { printf >&2 \"\n%s\n\n\" \"This repository is configured for Git LFS but 'git-lfs' was not found on your path. If you no longer wish to use Git LFS, remove this hook by deleting the 'post-commit' file in the hooks directory (set by 'core.hookspath'; usually '.git/hooks').\"; exit 2; }
197 git lfs post-commit \"\$@\"
198
199 Add the following to 'hooks/post-merge':
200
201 #!/bin/sh
202 command -v git-lfs >/dev/null 2>&1 || { printf >&2 \"\n%s\n\n\" \"This repository is configured for Git LFS but 'git-lfs' was not found on your path. If you no longer wish to use Git LFS, remove this hook by deleting the 'post-merge' file in the hooks directory (set by 'core.hookspath'; usually '.git/hooks').\"; exit 2; }
203 git lfs post-merge \"\$@\""
204 [scip-shell system . . `[`. "$expected" = "$(gitscip-shell system . . git. lfs update --manual 2>&1)" ]
205 [scip-shell system . . `[`. "test" = "$(catscip-shell system . . cat. hooks/pre-push)" ]
206 [scip-shell system . . `[`. "test" = "$(catscip-shell system . . cat. hooks/post-checkout)" ]
207 [scip-shell system . . `[`. "test" = "$(catscip-shell system . . cat. hooks/post-commit)" ]
208 [scip-shell system . . `[`. "test" = "$(catscip-shell system . . cat. hooks/post-merge)" ]
209
210 # force replace unexpected hook
211 [scip-shell system . . `[`. "Updated Git hooks." = "$(gitscip-shell system . . git. lfs update --force)" ]
212 [scip-shell system . . `[`. "$pre_push_hook" = "$(catscip-shell system . . cat. hooks/pre-push)" ]
213 [scip-shell system . . `[`. "$post_checkout_hook" = "$(catscip-shell system . . cat. hooks/post-checkout)" ]
214 [scip-shell system . . `[`. "$post_commit_hook" = "$(catscip-shell system . . cat. hooks/post-commit)" ]
215 [scip-shell system . . `[`. "$post_merge_hook" = "$(catscip-shell system . . cat. hooks/post-merge)" ]
216
217 testscip-shell system . . test. -d .git/hooks && exit 1
218 fi
219
220 has_test_dir || exit 0
221
222 echoscip-shell system . . echo. "test with bare repository"
223 cd ..
224 gitscip-shell system . . git. clone --mirror without-pre-push bare
225 cd bare
226 gitscip-shell system . . git. lfs env
227 gitscip-shell system . . git. lfs update
228 lsscip-shell system . . ls. -al hooks
229 [scip-shell system . . `[`. "$pre_push_hook" = "$(catscip-shell system . . cat. hooks/pre-push)" ]
230 )
231 end_test
232
233 begin_test "update with leading spaces"
234 (
235 set -e
236
237 reponame="update-leading-spaces"
238 gitscip-shell system . . git. init "$reponame"
239 cd "$reponame"
240
241 [scip-shell system . . `[`. "Updated Git hooks." = "$(gitscip-shell system . . git. lfs update)" ]
242
243 # $pre_push_hook contains leading TAB '\t' characters
244 pre_push_hook="#!/bin/sh
245 command -v git-lfs >/dev/null 2>&1 || { echo >&2 \"\\nThis repository is configured for Git LFS but 'git-lfs' was not found on your path. If you no longer wish to use Git LFS, remove this hook by deleting '.git/hooks/pre-push'.\\n\"; exit 2; }
246 git lfs pre-push \"\$@\""
247
248 echoscip-shell system . . echo. -n "$pre_push_hook" > .git/hooks/pre-push
249
250 [scip-shell system . . `[`. "Updated Git hooks." = "$(gitscip-shell system . . git. lfs update)" ]
251 )
252 end_test
253
254 begin_test "update lfs.{url}.access"
255 (
256 set -e
257
258 mkdirscip-shell system . . mkdir. update-access
259 cd update-access
260 gitscip-shell system . . git. init
261 gitscip-shell system . . git. config lfs.http://example.com.access private
262 gitscip-shell system . . git. config lfs.https://example.com.access private
263 gitscip-shell system . . git. config lfs.https://example2.com.access basic
264 gitscip-shell system . . git. config lfs.https://example3.com.access other
265
266 [scip-shell system . . `[`. "private" = "$(gitscip-shell system . . git. config lfs.http://example.com.access)" ]
267 [scip-shell system . . `[`. "private" = "$(gitscip-shell system . . git. config lfs.https://example.com.access)" ]
268 [scip-shell system . . `[`. "basic" = "$(gitscip-shell system . . git. config lfs.https://example2.com.access)" ]
269 [scip-shell system . . `[`. "other" = "$(gitscip-shell system . . git. config lfs.https://example3.com.access)" ]
270
271 expected="Updated Git hooks.
272 Updated http://example.com access from private to basic.
273 Updated https://example.com access from private to basic.
274 Removed invalid https://example3.com access of other."
275 )
276 end_test
277
278 begin_test "update: outside git repository"
279 (
280 if [scip-shell system . . `[`. -d "hooks" ]; then
281 lsscip-shell system . . ls. -al
282 echoscip-shell system . . echo. "hooks dir exists"
283 exit 1
284 fi
285
286 set +e
287 gitscip-shell system . . git. lfs update 2>&1 > check.log
288 res=$?
289 set -e
290
291 if [scip-shell system . . `[`. "$res" = "0" ]; then
292 if [scip-shell system . . `[`. -z "$GIT_LFS_TEST_DIR" ]; then
293 echoscip-shell system . . echo. "Passes because $GIT_LFS_TEST_DIR is unset."
294 exit 0
295 fi
296 fi
297
298 [scip-shell system . . `[`. "$res" = "128" ]
299
300 if [scip-shell system . . `[`. -d "hooks" ]; then
301 lsscip-shell system . . ls. -al
302 echoscip-shell system . . echo. "hooks dir exists"
303 exit 1
304 fi
305
306 catscip-shell system . . cat. check.log
307 grepscip-shell system . . grep. "Not in a Git repository" check.log
308 )
309 end_test