Debian Codegraph @

t/t-uninstall.sh

raw symbols SCIP
1 #!/usr/bin/env bash
2
3 . "$(dirname "$0")/testlib.sh"
4
5 begin_test "uninstall outside repository"
6 (
7 set -e
8
9 mkdir uninstall-test
10 cd uninstall-test
11
12 smudge="$(git config filter.lfs.smudge)"
13 clean="$(git config filter.lfs.clean)"
14 filter="$(git config filter.lfs.process)"
15
16 printf "%s" "$smudge" | grep "git-lfs smudge"
17 printf "%s" "$clean" | grep "git-lfs clean"
18 printf "%s" "$filter" | grep "git-lfs filter-process"
19
20 # uninstall multiple times to trigger https://github.com/git-lfs/git-lfs/issues/529
21 git lfs uninstall
22
23 [ ! -e "lfs" ]
24
25 for opt in "" "--skip-repo"
26 do
27 git lfs install
28 git lfs uninstall $opt | tee uninstall.log
29 grep "Global Git LFS configuration has been removed." uninstall.log
30
31 [ "" = "$(git config --global filter.lfs.smudge)" ]
32 [ "" = "$(git config --global filter.lfs.clean)" ]
33 [ "" = "$(git config --global filter.lfs.process)" ]
34
35 cat $HOME/.gitconfig
36 [ 0 -eq "$(grep -c 'filter "lfs"' $HOME/.gitconfig)" ]
37 done
38 )
39 end_test
40
41 begin_test "uninstall outside repository without access to .git/lfs"
42 (
43 set -e
44
45 mkdir uninstall-no-lfs
46 cd uninstall-no-lfs
47
48 mkdir .git
49 touch .git/lfs
50 touch lfs
51
52 [ "" != "$(git config --global filter.lfs.smudge)" ]
53 [ "" != "$(git config --global filter.lfs.clean)" ]
54 [ "" != "$(git config --global filter.lfs.process)" ]
55
56 git lfs uninstall
57
58 [ "" = "$(git config --global filter.lfs.smudge)" ]
59 [ "" = "$(git config --global filter.lfs.clean)" ]
60 [ "" = "$(git config --global filter.lfs.process)" ]
61 )
62
63 begin_test "uninstall inside repository with --skip-repo"
64 (
65 set -e
66
67 reponame="$(basename "$0" ".sh")-skip-repo"
68 mkdir "$reponame"
69 cd "$reponame"
70 git init
71 git lfs install
72
73 [ -f .git/hooks/pre-push ]
74 grep "git-lfs" .git/hooks/pre-push
75
76 [ "git-lfs smudge -- %f" = "$(git config filter.lfs.smudge)" ]
77 [ "git-lfs clean -- %f" = "$(git config filter.lfs.clean)" ]
78 [ "git-lfs filter-process" = "$(git config filter.lfs.process)" ]
79
80 git lfs uninstall --skip-repo
81
82 [ -f .git/hooks/pre-push ]
83 [ "" = "$(git config filter.lfs.smudge)" ]
84 [ "" = "$(git config filter.lfs.clean)" ]
85 [ "" = "$(git config filter.lfs.process)" ]
86 )
87 end_test
88
89 begin_test "uninstall inside repository with default pre-push hook"
90 (
91 set -e
92
93 reponame="$(basename "$0" ".sh")-hook"
94 mkdir "$reponame"
95 cd "$reponame"
96 git init
97 git lfs install
98
99 [ -f .git/hooks/pre-push ]
100 grep "git-lfs" .git/hooks/pre-push
101
102 [ "git-lfs smudge -- %f" = "$(git config filter.lfs.smudge)" ]
103 [ "git-lfs clean -- %f" = "$(git config filter.lfs.clean)" ]
104 [ "git-lfs filter-process" = "$(git config filter.lfs.process)" ]
105
106 git lfs uninstall
107
108 [ -f .git/hooks/pre-push ] && {
109 echo "expected .git/hooks/pre-push to be deleted"
110 exit 1
111 }
112 [ "" = "$(git config filter.lfs.smudge)" ]
113 [ "" = "$(git config filter.lfs.clean)" ]
114 [ "" = "$(git config filter.lfs.process)" ]
115 )
116 end_test
117
118 begin_test "uninstall inside repository without lfs pre-push hook"
119 (
120 set -e
121
122 reponame="$(basename "$0" ".sh")-no-hook"
123 mkdir "$reponame"
124 cd "$reponame"
125 git init
126 git lfs install
127 echo "something something git-lfs" > .git/hooks/pre-push
128
129
130 [ -f .git/hooks/pre-push ]
131 [ "something something git-lfs" = "$(cat .git/hooks/pre-push)" ]
132
133 [ "git-lfs smudge -- %f" = "$(git config filter.lfs.smudge)" ]
134 [ "git-lfs clean -- %f" = "$(git config filter.lfs.clean)" ]
135 [ "git-lfs filter-process" = "$(git config filter.lfs.process)" ]
136
137 git lfs uninstall
138
139 [ -f .git/hooks/pre-push ]
140 [ "" = "$(git config filter.lfs.smudge)" ]
141 [ "" = "$(git config filter.lfs.clean)" ]
142 [ "" = "$(git config filter.lfs.process)" ]
143 )
144 end_test
145
146 begin_test "uninstall hooks inside repository"
147 (
148 set -e
149
150 reponame="$(basename "$0" ".sh")-only-hook"
151 mkdir "$reponame"
152 cd "$reponame"
153 git init
154 git lfs install
155
156 [ -f .git/hooks/pre-push ]
157 grep "git-lfs" .git/hooks/pre-push
158
159 [ "git-lfs smudge -- %f" = "$(git config filter.lfs.smudge)" ]
160 [ "git-lfs clean -- %f" = "$(git config filter.lfs.clean)" ]
161 [ "git-lfs filter-process" = "$(git config filter.lfs.process)" ]
162
163 git lfs uninstall hooks
164
165 [ -f .git/hooks/pre-push ] && {
166 echo "expected .git/hooks/pre-push to be deleted"
167 exit 1
168 }
169
170 [ "git-lfs smudge -- %f" = "$(git config filter.lfs.smudge)" ]
171 [ "git-lfs clean -- %f" = "$(git config filter.lfs.clean)" ]
172 [ "git-lfs filter-process" = "$(git config filter.lfs.process)" ]
173 )
174 end_test
175
176 begin_test "uninstall --local outside repository"
177 (
178 set -e
179
180 # If run inside the git-lfs source dir this will update its .git/config & cause issues
181 if [ "$GIT_LFS_TEST_DIR" == "" ]; then
182 echo "Skipping uninstall --local because GIT_LFS_TEST_DIR is not set"
183 exit 0
184 fi
185
186 has_test_dir || exit 0
187
188 set +e
189 git lfs uninstall --local >out.log
190 res=$?
191 set -e
192
193 [ "Not in a Git repository." = "$(cat out.log)" ]
194 [ "0" != "$res" ]
195 )
196 end_test
197
198 begin_test "uninstall --local with conflicting scope"
199 (
200 set -e
201
202 reponame="$(basename "$0" ".sh")-scope-conflict"
203 mkdir "$reponame"
204 cd "$reponame"
205 git init
206
207 set +e
208 git lfs uninstall --local --system 2>err.log
209 res=$?
210 set -e
211
212 [ "Only one of the --local, --system, --worktree, and --file options can be specified." = "$(cat err.log)" ]
213 [ "0" != "$res" ]
214 )
215 end_test
216
217 begin_test "uninstall --local"
218 (
219 set -e
220
221 # old values that should be ignored by `uninstall --local`
222 git config --global filter.lfs.smudge "global smudge"
223 git config --global filter.lfs.clean "global clean"
224 git config --global filter.lfs.process "global filter"
225
226 reponame="$(basename "$0" ".sh")-local"
227 mkdir "$reponame"
228 cd "$reponame"
229 git init
230 git lfs install --local
231
232 # local configs are correct
233 [ "git-lfs smudge -- %f" = "$(git config filter.lfs.smudge)" ]
234 [ "git-lfs smudge -- %f" = "$(git config --local filter.lfs.smudge)" ]
235 [ "git-lfs clean -- %f" = "$(git config filter.lfs.clean)" ]
236 [ "git-lfs clean -- %f" = "$(git config --local filter.lfs.clean)" ]
237 [ "git-lfs filter-process" = "$(git config filter.lfs.process)" ]
238 [ "git-lfs filter-process" = "$(git config --local filter.lfs.process)" ]
239
240 # global configs
241 [ "global smudge" = "$(git config --global filter.lfs.smudge)" ]
242 [ "global clean" = "$(git config --global filter.lfs.clean)" ]
243 [ "global filter" = "$(git config --global filter.lfs.process)" ]
244
245 git lfs uninstall --local 2>&1 | tee uninstall.log
246 if [ ${PIPESTATUS[0]} -ne 0 ]; then
247 echo >&2 "fatal: expected 'git lfs uninstall --local' to succeed"
248 exit 1
249 fi
250 [ 0 -eq "$(grep -c "Global Git LFS configuration has been removed." uninstall.log)" ]
251
252 # global configs
253 [ "global smudge" = "$(git config filter.lfs.smudge)" ]
254 [ "global smudge" = "$(git config --global filter.lfs.smudge)" ]
255 [ "global clean" = "$(git config filter.lfs.clean)" ]
256 [ "global clean" = "$(git config --global filter.lfs.clean)" ]
257 [ "global filter" = "$(git config filter.lfs.process)" ]
258 [ "global filter" = "$(git config --global filter.lfs.process)" ]
259
260 # local configs are empty
261 [ "" = "$(git config --local filter.lfs.smudge)" ]
262 [ "" = "$(git config --local filter.lfs.clean)" ]
263 [ "" = "$(git config --local filter.lfs.process)" ]
264 )
265 end_test
266
267 begin_test "uninstall --file"
268 (
269 set -e
270
271 # old values that should be ignored by `uninstall --local`
272 git config --global filter.lfs.smudge "global smudge"
273 git config --global filter.lfs.clean "global clean"
274 git config --global filter.lfs.process "global filter"
275
276 reponame="$(basename "$0" ".sh")-file"
277 mkdir "$reponame"
278 cd "$reponame"
279 git init
280 git lfs install --file=test-file
281
282 # local configs are correct
283 [ "git-lfs smudge -- %f" = "$(git config --file test-file filter.lfs.smudge)" ]
284 [ "git-lfs clean -- %f" = "$(git config --file test-file filter.lfs.clean)" ]
285 [ "git-lfs filter-process" = "$(git config --file test-file filter.lfs.process)" ]
286
287 # global configs
288 [ "global smudge" = "$(git config --global filter.lfs.smudge)" ]
289 [ "global clean" = "$(git config --global filter.lfs.clean)" ]
290 [ "global filter" = "$(git config --global filter.lfs.process)" ]
291
292 git lfs uninstall --file=test-file 2>&1 | tee uninstall.log
293 if [ ${PIPESTATUS[0]} -ne 0 ]; then
294 echo >&2 "fatal: expected 'git lfs uninstall --file=test-file' to succeed"
295 exit 1
296 fi
297 # At present, we expect this message to always be output because the --file
298 # option was intended for use with alternative global configuration files
299 # like $XDG_CONFIG_HOME/git/config, although users may in practice use the
300 # the --file option on arbitrary files.
301 grep "Global Git LFS configuration has been removed." uninstall.log
302
303 # global configs
304 [ "global smudge" = "$(git config filter.lfs.smudge)" ]
305 [ "global smudge" = "$(git config --global filter.lfs.smudge)" ]
306 [ "global clean" = "$(git config filter.lfs.clean)" ]
307 [ "global clean" = "$(git config --global filter.lfs.clean)" ]
308 [ "global filter" = "$(git config filter.lfs.process)" ]
309 [ "global filter" = "$(git config --global filter.lfs.process)" ]
310
311 # local configs are empty
312 [ "" = "$(git config --file test-file filter.lfs.smudge)" ]
313 [ "" = "$(git config --file test-file filter.lfs.clean)" ]
314 [ "" = "$(git config --file test-file filter.lfs.process)" ]
315 )
316 end_test