Debian Codegraph @

t/t-uninstall-worktree.sh

raw symbols SCIP
1 #!/usr/bin/env bash
2
3 . "$(dirname "$0")/testlib.sh"
4
5 # These tests rely on behavior found in Git versions higher than 2.20.0 to
6 # perform themselves, specifically:
7 # - worktreeConfig extension support
8 ensure_git_version_isnt $VERSION_LOWER "2.20.0"
9
10 begin_test "uninstall --worktree outside repository"
11 (
12 set -e
13
14 # If run inside the git-lfs source dir this will update its .git/config & cause issues
15 if [ "$GIT_LFS_TEST_DIR" == "" ]; then
16 echo "Skipping uninstall --worktree because GIT_LFS_TEST_DIR is not set"
17 exit 0
18 fi
19
20 has_test_dir || exit 0
21
22 set +e
23 git lfs uninstall --worktree >out.log
24 res=$?
25 set -e
26
27 [ "Not in a Git repository." = "$(cat out.log)" ]
28 [ "0" != "$res" ]
29 )
30 end_test
31
32 begin_test "uninstall --worktree with single working tree"
33 (
34 set -e
35
36 # old values that should be ignored by `uninstall --worktree`
37 git config --global filter.lfs.smudge "global smudge"
38 git config --global filter.lfs.clean "global clean"
39 git config --global filter.lfs.process "global filter"
40
41 reponame="$(basename "$0" ".sh")-single-tree"
42 mkdir "$reponame"
43 cd "$reponame"
44 git init
45 git lfs install --worktree
46
47 # local configs are correct
48 [ "git-lfs smudge -- %f" = "$(git config filter.lfs.smudge)" ]
49 [ "git-lfs smudge -- %f" = "$(git config --local filter.lfs.smudge)" ]
50 [ "git-lfs smudge -- %f" = "$(git config --worktree filter.lfs.smudge)" ]
51 [ "git-lfs clean -- %f" = "$(git config filter.lfs.clean)" ]
52 [ "git-lfs clean -- %f" = "$(git config --local filter.lfs.clean)" ]
53 [ "git-lfs clean -- %f" = "$(git config --worktree filter.lfs.clean)" ]
54 [ "git-lfs filter-process" = "$(git config filter.lfs.process)" ]
55 [ "git-lfs filter-process" = "$(git config --local filter.lfs.process)" ]
56 [ "git-lfs filter-process" = "$(git config --worktree filter.lfs.process)" ]
57
58 # global configs
59 [ "global smudge" = "$(git config --global filter.lfs.smudge)" ]
60 [ "global clean" = "$(git config --global filter.lfs.clean)" ]
61 [ "global filter" = "$(git config --global filter.lfs.process)" ]
62
63 git lfs uninstall --worktree 2>&1 | tee uninstall.log
64 if [ ${PIPESTATUS[0]} -ne 0 ]; then
65 echo >&2 "fatal: expected 'git lfs uninstall --worktree' to succeed"
66 exit 1
67 fi
68 [ 0 -eq "$(grep -c "Global Git LFS configuration has been removed." uninstall.log)" ]
69
70 # global configs
71 [ "global smudge" = "$(git config filter.lfs.smudge)" ]
72 [ "global smudge" = "$(git config --global filter.lfs.smudge)" ]
73 [ "global clean" = "$(git config filter.lfs.clean)" ]
74 [ "global clean" = "$(git config --global filter.lfs.clean)" ]
75 [ "global filter" = "$(git config filter.lfs.process)" ]
76 [ "global filter" = "$(git config --global filter.lfs.process)" ]
77
78 # local configs are empty
79 [ "" = "$(git config --local filter.lfs.smudge)" ]
80 [ "" = "$(git config --worktree filter.lfs.smudge)" ]
81 [ "" = "$(git config --local filter.lfs.clean)" ]
82 [ "" = "$(git config --worktree filter.lfs.clean)" ]
83 [ "" = "$(git config --local filter.lfs.process)" ]
84 [ "" = "$(git config --worktree filter.lfs.process)" ]
85 )
86 end_test
87
88 begin_test "uninstall --worktree with multiple working trees"
89 (
90 set -e
91
92 reponame="$(basename "$0" ".sh")-multi-tree"
93 mkdir "$reponame"
94 cd "$reponame"
95 git init
96
97 # old values that should be ignored by `uninstall --worktree`
98 git config --global filter.lfs.smudge "global smudge"
99 git config --global filter.lfs.clean "global clean"
100 git config --global filter.lfs.process "global filter"
101 git config --local filter.lfs.smudge "local smudge"
102 git config --local filter.lfs.clean "local clean"
103 git config --local filter.lfs.process "local filter"
104
105 touch a.txt
106 git add a.txt
107 git commit -m "initial commit"
108
109 git config core.repositoryformatversion 1
110 git config extensions.worktreeConfig true
111
112 treename="../$reponame-wt"
113 git worktree add "$treename"
114 cd "$treename"
115
116 git lfs install --worktree
117
118 # worktree configs are correct
119 [ "git-lfs smudge -- %f" = "$(git config filter.lfs.smudge)" ]
120 [ "git-lfs smudge -- %f" = "$(git config --worktree filter.lfs.smudge)" ]
121 [ "git-lfs clean -- %f" = "$(git config filter.lfs.clean)" ]
122 [ "git-lfs clean -- %f" = "$(git config --worktree filter.lfs.clean)" ]
123 [ "git-lfs filter-process" = "$(git config filter.lfs.process)" ]
124 [ "git-lfs filter-process" = "$(git config --worktree filter.lfs.process)" ]
125
126 # local configs are correct
127 [ "local smudge" = "$(git config --local filter.lfs.smudge)" ]
128 [ "local clean" = "$(git config --local filter.lfs.clean)" ]
129 [ "local filter" = "$(git config --local filter.lfs.process)" ]
130
131 # global configs
132 [ "global smudge" = "$(git config --global filter.lfs.smudge)" ]
133 [ "global clean" = "$(git config --global filter.lfs.clean)" ]
134 [ "global filter" = "$(git config --global filter.lfs.process)" ]
135
136 git lfs uninstall --worktree 2>&1 | tee uninstall.log
137 if [ ${PIPESTATUS[0]} -ne 0 ]; then
138 echo >&2 "fatal: expected 'git lfs uninstall --worktree' to succeed"
139 exit 1
140 fi
141 [ 0 -eq "$(grep -c "Global Git LFS configuration has been removed." uninstall.log)" ]
142
143 # global configs
144 [ "global smudge" = "$(git config --global filter.lfs.smudge)" ]
145 [ "global clean" = "$(git config --global filter.lfs.clean)" ]
146 [ "global filter" = "$(git config --global filter.lfs.process)" ]
147
148 # local configs
149 [ "local smudge" = "$(git config filter.lfs.smudge)" ]
150 [ "local smudge" = "$(git config --local filter.lfs.smudge)" ]
151 [ "local clean" = "$(git config filter.lfs.clean)" ]
152 [ "local clean" = "$(git config --local filter.lfs.clean)" ]
153 [ "local filter" = "$(git config filter.lfs.process)" ]
154 [ "local filter" = "$(git config --local filter.lfs.process)" ]
155
156 # worktree configs are empty
157 [ "" = "$(git config --worktree filter.lfs.smudge)" ]
158 [ "" = "$(git config --worktree filter.lfs.clean)" ]
159 [ "" = "$(git config --worktree filter.lfs.process)" ]
160 )
161 end_test
162
163 begin_test "uninstall --worktree without worktreeConfig extension"
164 (
165 set -e
166
167 reponame="$(basename "$0" ".sh")-multi-tree-no-config"
168 mkdir "$reponame"
169 cd "$reponame"
170 git init
171
172 touch a.txt
173 git add a.txt
174 git commit -m "initial commit"
175
176 treename="../$reponame-wt"
177 git worktree add "$treename"
178 cd "$treename"
179
180 set +e
181 git lfs uninstall --worktree >out.log
182 res=$?
183 set -e
184
185 cat out.log
186 grep -E "error running.*git.*config" out.log
187 [ "$res" -eq 0 ]
188 )
189 end_test
190
191 begin_test "uninstall --worktree with conflicting scope"
192 (
193 set -e
194
195 reponame="$(basename "$0" ".sh")-scope-conflict"
196 mkdir "$reponame"
197 cd "$reponame"
198 git init
199
200 set +e
201 git lfs uninstall --local --worktree 2>err.log
202 res=$?
203 set -e
204
205 [ "Only one of the --local, --system, --worktree, and --file options can be specified." = "$(cat err.log)" ]
206 [ "0" != "$res" ]
207
208 set +e
209 git lfs uninstall --worktree --system 2>err.log
210 res=$?
211 set -e
212
213 [ "Only one of the --local, --system, --worktree, and --file options can be specified." = "$(cat err.log)" ]
214 [ "0" != "$res" ]
215
216 set +e
217 git lfs uninstall --worktree --file test-file 2>err.log
218 res=$?
219 set -e
220
221 [ "Only one of the --local, --system, --worktree, and --file options can be specified." = "$(cat err.log)" ]
222 [ "0" != "$res" ]
223 )
224 end_test