Imported Upstream version 2.5.1
[scm/test.git] / t / t-uninstall.sh
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 "$smudge" | grep "git-lfs smudge"
17   printf "$clean" | grep "git-lfs clean"
18   printf "$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   git lfs install
26   git lfs uninstall | tee uninstall.log
27   grep "configuration has been removed" uninstall.log
28
29   [ "" = "$(git config --global filter.lfs.smudge)" ]
30   [ "" = "$(git config --global filter.lfs.clean)" ]
31   [ "" = "$(git config --global filter.lfs.process)" ]
32
33   cat $HOME/.gitconfig
34   [ "$(grep 'filter "lfs"' $HOME/.gitconfig -c)" = "0" ]
35 )
36 end_test
37
38 begin_test "uninstall outside repository without access to .git/lfs"
39 (
40   set -e
41
42   mkdir uninstall-no-lfs
43   cd uninstall-no-lfs
44
45   mkdir .git
46   touch .git/lfs
47   touch lfs
48
49   [ "" != "$(git config --global filter.lfs.smudge)" ]
50   [ "" != "$(git config --global filter.lfs.clean)" ]
51   [ "" != "$(git config --global filter.lfs.process)" ]
52
53   git lfs uninstall
54
55   [ "" = "$(git config --global filter.lfs.smudge)" ]
56   [ "" = "$(git config --global filter.lfs.clean)" ]
57   [ "" = "$(git config --global filter.lfs.process)" ]
58 )
59
60 begin_test "uninstall inside repository with default pre-push hook"
61 (
62   set -e
63
64   reponame="$(basename "$0" ".sh")-hook"
65   mkdir "$reponame"
66   cd "$reponame"
67   git init
68   git lfs install
69
70   [ -f .git/hooks/pre-push ]
71   grep "git-lfs" .git/hooks/pre-push
72
73   [ "git-lfs smudge -- %f" = "$(git config filter.lfs.smudge)" ]
74   [ "git-lfs clean -- %f" = "$(git config filter.lfs.clean)" ]
75   [ "git-lfs filter-process" = "$(git config filter.lfs.process)" ]
76
77   git lfs uninstall
78
79   [ -f .git/hooks/pre-push ] && {
80     echo "expected .git/hooks/pre-push to be deleted"
81     exit 1
82   }
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 without lfs pre-push hook"
90 (
91   set -e
92
93   reponame="$(basename "$0" ".sh")-no-hook"
94   mkdir "$reponame"
95   cd "$reponame"
96   git init
97   git lfs install
98   echo "something something git-lfs" > .git/hooks/pre-push
99
100
101   [ -f .git/hooks/pre-push ]
102   [ "something something git-lfs" = "$(cat .git/hooks/pre-push)" ]
103
104   [ "git-lfs smudge -- %f" = "$(git config filter.lfs.smudge)" ]
105   [ "git-lfs clean -- %f" = "$(git config filter.lfs.clean)" ]
106   [ "git-lfs filter-process" = "$(git config filter.lfs.process)" ]
107
108   git lfs uninstall
109
110   [ -f .git/hooks/pre-push ]
111   [ "" = "$(git config filter.lfs.smudge)" ]
112   [ "" = "$(git config filter.lfs.clean)" ]
113   [ "" = "$(git config filter.lfs.process)" ]
114 )
115 end_test
116
117 begin_test "uninstall hooks inside repository"
118 (
119   set -e
120
121   reponame="$(basename "$0" ".sh")-only-hook"
122   mkdir "$reponame"
123   cd "$reponame"
124   git init
125   git lfs install
126
127   [ -f .git/hooks/pre-push ]
128   grep "git-lfs" .git/hooks/pre-push
129
130   [ "git-lfs smudge -- %f" = "$(git config filter.lfs.smudge)" ]
131   [ "git-lfs clean -- %f" = "$(git config filter.lfs.clean)" ]
132   [ "git-lfs filter-process" = "$(git config filter.lfs.process)" ]
133
134   git lfs uninstall hooks
135
136   [ -f .git/hooks/pre-push ] && {
137     echo "expected .git/hooks/pre-push to be deleted"
138     exit 1
139   }
140
141   [ "git-lfs smudge -- %f" = "$(git config filter.lfs.smudge)" ]
142   [ "git-lfs clean -- %f" = "$(git config filter.lfs.clean)" ]
143   [ "git-lfs filter-process" = "$(git config filter.lfs.process)" ]
144 )
145 end_test
146
147 begin_test "uninstall --local"
148 (
149   set -e
150
151   # old values that should be ignored by `uninstall --local`
152   git config --global filter.lfs.smudge "global smudge"
153   git config --global filter.lfs.clean "global clean"
154   git config --global filter.lfs.process "global filter"
155
156   reponame="$(basename "$0" ".sh")-local"
157   mkdir "$reponame"
158   cd "$reponame"
159   git init
160   git lfs install --local
161
162   # local configs are correct
163   [ "git-lfs smudge -- %f" = "$(git config --local filter.lfs.smudge)" ]
164   [ "git-lfs clean -- %f" = "$(git config --local filter.lfs.clean)" ]
165   [ "git-lfs filter-process" = "$(git config --local filter.lfs.process)" ]
166
167   # global configs
168   [ "global smudge" = "$(git config --global filter.lfs.smudge)" ]
169   [ "global clean" = "$(git config --global filter.lfs.clean)" ]
170   [ "global filter" = "$(git config --global filter.lfs.process)" ]
171
172   git lfs uninstall --local 2>&1 | tee uninstall.log
173   if [ ${PIPESTATUS[0]} -ne 0 ]; then
174     echo >&2 "fatal: expected 'git lfs uninstall --local' to succeed"
175     exit 1
176   fi
177   grep -v "Global Git LFS configuration has been removed." uninstall.log
178
179   # global configs
180   [ "global smudge" = "$(git config --global filter.lfs.smudge)" ]
181   [ "global clean" = "$(git config --global filter.lfs.clean)" ]
182   [ "global filter" = "$(git config --global filter.lfs.process)" ]
183
184   # local configs are empty
185   [ "" = "$(git config --local filter.lfs.smudge)" ]
186   [ "" = "$(git config --local filter.lfs.clean)" ]
187   [ "" = "$(git config --local filter.lfs.process)" ]
188 )
189 end_test