Imported Upstream version 2.5.1
[scm/test.git] / t / t-push-failures-local.sh
1 #!/usr/bin/env bash
2
3 . "$(dirname "$0")/testlib.sh"
4
5 begin_test "push with missing objects (lfs.allowincompletepush true)"
6 (
7   set -e
8
9   reponame="push-with-missing-objects"
10   setup_remote_repo "$reponame"
11   clone_repo "$reponame" "$reponame"
12
13   git lfs track "*.dat"
14   git add .gitattributes
15   git commit -m "initial commit"
16
17   present="present"
18   present_oid="$(calc_oid "$present")"
19   printf "$present" > present.dat
20
21   missing="missing"
22   missing_oid="$(calc_oid "$missing")"
23   printf "$missing" > missing.dat
24
25   git add missing.dat present.dat
26   git commit -m "add objects"
27
28   git rm missing.dat
29   git commit -m "remove missing"
30
31   # :fire: the "missing" object
32   missing_oid_part_1="$(echo "$missing_oid" | cut -b 1-2)"
33   missing_oid_part_2="$(echo "$missing_oid" | cut -b 3-4)"
34   missing_oid_path=".git/lfs/objects/$missing_oid_part_1/$missing_oid_part_2/$missing_oid"
35   rm "$missing_oid_path"
36
37   git config lfs.allowincompletepush true
38
39   git push origin master 2>&1 | tee push.log
40   if [ "0" -ne "${PIPESTATUS[0]}" ]; then
41     echo >&2 "fatal: expected \`git push origin master\` to succeed ..."
42     exit 1
43   fi
44
45   grep "LFS upload missing objects" push.log
46   grep "  (missing) missing.dat ($missing_oid)" push.log
47
48   assert_server_object "$reponame" "$present_oid"
49   refute_server_object "$reponame" "$missing_oid"
50 )
51 end_test
52
53 begin_test "push reject missing objects (lfs.allowincompletepush false)"
54 (
55   set -e
56
57   reponame="push-reject-missing-objects"
58   setup_remote_repo "$reponame"
59   clone_repo "$reponame" "$reponame"
60
61   git lfs track "*.dat"
62   git add .gitattributes
63   git commit -m "initial commit"
64
65   present="present"
66   present_oid="$(calc_oid "$present")"
67   printf "$present" > present.dat
68
69   missing="missing"
70   missing_oid="$(calc_oid "$missing")"
71   printf "$missing" > missing.dat
72
73   git add missing.dat present.dat
74   git commit -m "add objects"
75
76   git rm missing.dat
77   git commit -m "remove missing"
78
79   # :fire: the "missing" object
80   missing_oid_part_1="$(echo "$missing_oid" | cut -b 1-2)"
81   missing_oid_part_2="$(echo "$missing_oid" | cut -b 3-4)"
82   missing_oid_path=".git/lfs/objects/$missing_oid_part_1/$missing_oid_part_2/$missing_oid"
83   rm "$missing_oid_path"
84
85   git config lfs.allowincompletepush false
86
87   git push origin master 2>&1 | tee push.log
88   if [ "1" -ne "${PIPESTATUS[0]}" ]; then
89     echo >&2 "fatal: expected \`git push origin master\` to succeed ..."
90     exit 1
91   fi
92
93   grep "no such file or directory" push.log || # unix
94     grep "cannot find the file" push.log       # windows
95   grep "failed to push some refs" push.log
96
97   refute_server_object "$reponame" "$present_oid"
98   refute_server_object "$reponame" "$missing_oid"
99 )
100 end_test
101
102 begin_test "push reject missing objects (lfs.allowincompletepush default)"
103 (
104   set -e
105
106   reponame="push-missing-objects"
107   setup_remote_repo "$reponame"
108   clone_repo "$reponame" "$reponame"
109
110   git lfs track "*.dat"
111   git add .gitattributes
112   git commit -m "initial commit"
113
114   missing="missing"
115   missing_oid="$(calc_oid "$missing")"
116   missing_len="$(printf "$missing" | wc -c | awk '{ print $1 }')"
117   printf "$missing" > missing.dat
118   git add missing.dat
119   git commit -m "add missing.dat"
120
121   present="present"
122   present_oid="$(calc_oid "$present")"
123   present_len="$(printf "$present" | wc -c | awk '{ print $1 }')"
124   printf "$present" > present.dat
125   git add present.dat
126   git commit -m "add present.dat"
127
128   assert_local_object "$missing_oid" "$missing_len"
129   assert_local_object "$present_oid" "$present_len"
130
131   delete_local_object "$missing_oid"
132
133   refute_local_object "$missing_oid"
134   assert_local_object "$present_oid" "$present_len"
135
136   git push origin master 2>&1 | tee push.log
137
138   if [ "0" -eq "${PIPESTATUS[0]}" ]; then
139     echo >&2 "fatal: expected 'git push origin master' to exit with non-zero code"
140     exit 1
141   fi
142
143   grep "LFS upload failed:" push.log
144   grep "  (missing) missing.dat ($missing_oid)" push.log
145
146   refute_server_object "$reponame" "$missing_oid"
147   assert_server_object "$reponame" "$present_oid"
148 )
149 end_test
150
151 begin_test "push reject corrupt objects (lfs.allowincompletepush default)"
152 (
153   set -e
154
155   reponame="push-corrupt-objects"
156   setup_remote_repo "$reponame"
157   clone_repo "$reponame" "$reponame"
158
159   git lfs track "*.dat"
160   git add .gitattributes
161   git commit -m "initial commit"
162
163   corrupt="corrupt"
164   corrupt_oid="$(calc_oid "$corrupt")"
165   corrupt_len="$(printf "$corrupt" | wc -c | awk '{ print $1 }')"
166   printf "$corrupt" > corrupt.dat
167   git add corrupt.dat
168   git commit -m "add corrupt.dat"
169
170   present="present"
171   present_oid="$(calc_oid "$present")"
172   present_len="$(printf "$present" | wc -c | awk '{ print $1 }')"
173   printf "$present" > present.dat
174   git add present.dat
175   git commit -m "add present.dat"
176
177   assert_local_object "$corrupt_oid" "$corrupt_len"
178   assert_local_object "$present_oid" "$present_len"
179
180   corrupt_local_object "$corrupt_oid"
181
182   refute_local_object "$corrupt_oid" "$corrupt_len"
183   assert_local_object "$present_oid" "$present_len"
184
185   git push origin master 2>&1 | tee push.log
186
187   if [ "0" -eq "${PIPESTATUS[0]}" ]; then
188     echo >&2 "fatal: expected 'git push origin master' to exit with non-zero code"
189     exit 1
190   fi
191
192   grep "LFS upload failed:" push.log
193   grep "  (corrupt) corrupt.dat ($corrupt_oid)" push.log
194
195   refute_server_object "$reponame" "$corrupt_oid"
196   assert_server_object "$reponame" "$present_oid"
197 )
198 end_test