3 . "$(dirname "$0")/testlib.sh"
5 begin_test "push with missing objects (lfs.allowincompletepush true)"
9 reponame="push-with-missing-objects"
10 setup_remote_repo "$reponame"
11 clone_repo "$reponame" "$reponame"
14 git add .gitattributes
15 git commit -m "initial commit"
18 present_oid="$(calc_oid "$present")"
19 printf "$present" > present.dat
22 missing_oid="$(calc_oid "$missing")"
23 printf "$missing" > missing.dat
25 git add missing.dat present.dat
26 git commit -m "add objects"
29 git commit -m "remove missing"
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"
37 git config lfs.allowincompletepush true
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 ..."
45 grep "LFS upload missing objects" push.log
46 grep " (missing) missing.dat ($missing_oid)" push.log
48 assert_server_object "$reponame" "$present_oid"
49 refute_server_object "$reponame" "$missing_oid"
53 begin_test "push reject missing objects (lfs.allowincompletepush false)"
57 reponame="push-reject-missing-objects"
58 setup_remote_repo "$reponame"
59 clone_repo "$reponame" "$reponame"
62 git add .gitattributes
63 git commit -m "initial commit"
66 present_oid="$(calc_oid "$present")"
67 printf "$present" > present.dat
70 missing_oid="$(calc_oid "$missing")"
71 printf "$missing" > missing.dat
73 git add missing.dat present.dat
74 git commit -m "add objects"
77 git commit -m "remove missing"
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"
85 git config lfs.allowincompletepush false
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 ..."
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
97 refute_server_object "$reponame" "$present_oid"
98 refute_server_object "$reponame" "$missing_oid"
102 begin_test "push reject missing objects (lfs.allowincompletepush default)"
106 reponame="push-missing-objects"
107 setup_remote_repo "$reponame"
108 clone_repo "$reponame" "$reponame"
110 git lfs track "*.dat"
111 git add .gitattributes
112 git commit -m "initial commit"
115 missing_oid="$(calc_oid "$missing")"
116 missing_len="$(printf "$missing" | wc -c | awk '{ print $1 }')"
117 printf "$missing" > missing.dat
119 git commit -m "add missing.dat"
122 present_oid="$(calc_oid "$present")"
123 present_len="$(printf "$present" | wc -c | awk '{ print $1 }')"
124 printf "$present" > present.dat
126 git commit -m "add present.dat"
128 assert_local_object "$missing_oid" "$missing_len"
129 assert_local_object "$present_oid" "$present_len"
131 delete_local_object "$missing_oid"
133 refute_local_object "$missing_oid"
134 assert_local_object "$present_oid" "$present_len"
136 git push origin master 2>&1 | tee push.log
138 if [ "0" -eq "${PIPESTATUS[0]}" ]; then
139 echo >&2 "fatal: expected 'git push origin master' to exit with non-zero code"
143 grep "LFS upload failed:" push.log
144 grep " (missing) missing.dat ($missing_oid)" push.log
146 refute_server_object "$reponame" "$missing_oid"
147 assert_server_object "$reponame" "$present_oid"
151 begin_test "push reject corrupt objects (lfs.allowincompletepush default)"
155 reponame="push-corrupt-objects"
156 setup_remote_repo "$reponame"
157 clone_repo "$reponame" "$reponame"
159 git lfs track "*.dat"
160 git add .gitattributes
161 git commit -m "initial commit"
164 corrupt_oid="$(calc_oid "$corrupt")"
165 corrupt_len="$(printf "$corrupt" | wc -c | awk '{ print $1 }')"
166 printf "$corrupt" > corrupt.dat
168 git commit -m "add corrupt.dat"
171 present_oid="$(calc_oid "$present")"
172 present_len="$(printf "$present" | wc -c | awk '{ print $1 }')"
173 printf "$present" > present.dat
175 git commit -m "add present.dat"
177 assert_local_object "$corrupt_oid" "$corrupt_len"
178 assert_local_object "$present_oid" "$present_len"
180 corrupt_local_object "$corrupt_oid"
182 refute_local_object "$corrupt_oid" "$corrupt_len"
183 assert_local_object "$present_oid" "$present_len"
185 git push origin master 2>&1 | tee push.log
187 if [ "0" -eq "${PIPESTATUS[0]}" ]; then
188 echo >&2 "fatal: expected 'git push origin master' to exit with non-zero code"
192 grep "LFS upload failed:" push.log
193 grep " (corrupt) corrupt.dat ($corrupt_oid)" push.log
195 refute_server_object "$reponame" "$corrupt_oid"
196 assert_server_object "$reponame" "$present_oid"