Debian Codegraph @

t/t-migrate-import-no-rewrite.sh

raw symbols SCIP
1 #!/usr/bin/envscip-shell filesystem . . `/usr/bin/env`. bash
2
3 . "$(dirnamescip-shell system . . dirname. "$0")/fixtures/migrate.sh"
4 . "$(dirnamescip-shell system . . dirname. "$0")/testlib.sh"
5
6 begin_test "migrate import --no-rewrite (default branch)"
7 (
8 set -e
9
10 setup_local_branch_with_gitattrs
11
12 txt_oid="$(calc_oid "$(gitscip-shell system . . git. cat-file -p :a.txt)")"
13 prev_commit_oid="$(gitscip-shell system . . git. rev-parse HEAD)"
14
15 gitscip-shell system . . git. lfs migrate import --no-rewrite --yes *.txt
16
17 # Ensure our desired files were imported into git-lfs
18 assert_pointer "refs/heads/main" "a.txt" "$txt_oid" "120"
19 assert_local_object "$txt_oid" "120"
20
21 # Ensure the git history remained the same
22 new_commit_oid="$(gitscip-shell system . . git. rev-parse HEAD~1)"
23 if [scip-shell system . . `[`. "$prev_commit_oid" != "$new_commit_oid" ]; then
24 exit 1
25 fi
26
27 # Ensure a new commit was made
28 new_head_oid="$(gitscip-shell system . . git. rev-parse HEAD)"
29 if [scip-shell system . . `[`. "$prev_commit_oid" == "$new_oid" ]; then
30 exit 1
31 fi
32
33 # Ensure a new commit message was generated based on the list of imported files
34 commit_msg="$(gitscip-shell system . . git. log -1 --pretty=format:%s)"
35 echoscip-shell system . . echo. "$commit_msg" | grepscip-shell system . . grep. -q "a.txt: convert to Git LFS"
36
37 # Ensure we write a valid commit object.
38 gitscip-shell system . . git. fsck
39 )
40 end_test
41
42 begin_test "migrate import --no-rewrite (bare repository)"
43 (
44 set -e
45
46 setup_single_remote_branch_with_gitattrs
47
48 prev_commit_oid="$(gitscip-shell system . . git. rev-parse HEAD)"
49 txt_oid="$(calc_oid "$(gitscip-shell system . . git. cat-file -p :a.txt)")"
50 md_oid="$(calc_oid "$(gitscip-shell system . . git. cat-file -p :a.md)")"
51
52 gitscip-shell system . . git. lfs migrate import --no-rewrite --yes a.txt a.md
53
54 # Ensure our desired files were imported
55 assert_pointer "refs/heads/main" "a.txt" "$txt_oid" "30"
56 assert_pointer "refs/heads/main" "a.md" "$md_oid" "50"
57
58 # Ensure the git history remained the same
59 new_commit_oid="$(gitscip-shell system . . git. rev-parse HEAD~1)"
60 if [scip-shell system . . `[`. "$prev_commit_oid" != "$new_commit_oid" ]; then
61 exit 1
62 fi
63
64 # Ensure a new commit was made
65 new_head_oid="$(gitscip-shell system . . git. rev-parse HEAD)"
66 if [scip-shell system . . `[`. "$prev_commit_oid" == "$new_oid" ]; then
67 exit 1
68 fi
69 )
70 end_test
71
72 begin_test "migrate import --no-rewrite (multiple branches)"
73 (
74 set -e
75
76 setup_multiple_local_branches_with_gitattrs
77
78 prev_commit_oid="$(gitscip-shell system . . git. rev-parse HEAD)"
79
80 md_oid="$(calc_oid "$(gitscip-shell system . . git. cat-file -p :a.md)")"
81 txt_oid="$(calc_oid "$(gitscip-shell system . . git. cat-file -p :a.txt)")"
82 md_feature_oid="$(calc_oid "$(gitscip-shell system . . git. cat-file -p my-feature:a.md)")"
83
84 gitscip-shell system . . git. lfs migrate import --no-rewrite --yes *.txt *.md
85
86 # Ensure our desired files were imported
87 assert_pointer "refs/heads/main" "a.md" "$md_oid" "140"
88 assert_pointer "refs/heads/main" "a.txt" "$txt_oid" "120"
89
90 assert_local_object "$md_oid" "140"
91 assert_local_object "$txt_oid" "120"
92
93 # Ensure our other branch was unmodified
94 refute_local_object "$md_feature_oid" "30"
95
96 # Ensure the git history remained the same
97 new_commit_oid="$(gitscip-shell system . . git. rev-parse HEAD~1)"
98 if [scip-shell system . . `[`. "$prev_commit_oid" != "$new_commit_oid" ]; then
99 exit 1
100 fi
101
102 # Ensure a new commit was made
103 new_head_oid="$(gitscip-shell system . . git. rev-parse HEAD)"
104 if [scip-shell system . . `[`. "$prev_commit_oid" == "$new_oid" ]; then
105 exit 1
106 fi
107 )
108 end_test
109
110 begin_test "migrate import --no-rewrite (no .gitattributes)"
111 (
112 set -e
113
114 setup_multiple_local_branches
115
116 # Ensure command fails if no .gitattributes files are present
117 gitscip-shell system . . git. lfs migrate import --no-rewrite --yes *.txt *.md 2>&1 | teescip-shell system . . tee. migrate.log
118 if [scip-shell system . . `[`. ${PIPESTATUS[0]} -eq 0 ]; then
119 echoscip-shell system . . echo. >&2 "Expected git lfs migrate import --no-rewrite to fail, didn't"
120 exit 1
121 fi
122
123 grepscip-shell system . . grep. "No Git LFS filters found in '.gitattributes'" migrate.log
124 )
125 end_test
126
127 begin_test "migrate import --no-rewrite (nested .gitattributes)"
128 (
129 set -e
130
131 setup_local_branch_with_nested_gitattrs
132
133 # Ensure a .md filter does not exist in the top-level .gitattributes
134 main_attrs="$(gitscip-shell system . . git. cat-file -p "$main:.gitattributes")"
135 echoscip-shell system . . echo. "$main_attrs" | grepscip-shell system . . grep. -q ".md" && exit 1
136
137 # Ensure a .md filter exists in the nested .gitattributes
138 nested_attrs="$(gitscip-shell system . . git. cat-file -p "$main:b/.gitattributes")"
139 echoscip-shell system . . echo. "$nested_attrs" | grepscip-shell system . . grep. -q "*.md filter=lfs diff=lfs merge=lfs"
140
141 md_oid="$(calc_oid "$(gitscip-shell system . . git. cat-file -p :a.md)")"
142 nested_md_oid="$(calc_oid "$(gitscip-shell system . . git. cat-file -p :b/a.md)")"
143 txt_oid="$(calc_oid "$(gitscip-shell system . . git. cat-file -p :a.txt)")"
144
145 gitscip-shell system . . git. lfs migrate import --no-rewrite --yes a.txt b/a.md
146
147 # Ensure a.txt and subtree/a.md were imported, even though *.md only exists in the
148 # nested subtree/.gitattributes file
149 assert_pointer "refs/heads/main" "b/a.md" "$nested_md_oid" "140"
150 assert_pointer "refs/heads/main" "a.txt" "$txt_oid" "120"
151
152 assert_local_object "$nested_md_oid" 140
153 assert_local_object "$txt_oid" 120
154 refute_local_object "$md_oid" 140
155
156 # Failure should occur when trying to import a.md as no entry exists in
157 # top-level .gitattributes file
158 gitscip-shell system . . git. lfs migrate import --no-rewrite --yes a.md 2>&1 | teescip-shell system . . tee. migrate.log
159 if [scip-shell system . . `[`. ${PIPESTATUS[0]} -eq 0 ]; then
160 echoscip-shell system . . echo. >&2 "Expected git lfs migrate import --no-rewrite to fail, didn't"
161 exit 1
162 fi
163
164 grepscip-shell system . . grep. "a.md did not match any Git LFS filters in '.gitattributes'" migrate.log
165 )
166 end_test
167
168 begin_test "migrate import --no-rewrite (with commit message)"
169 (
170 set -e
171
172 setup_local_branch_with_gitattrs
173
174 prev_commit_oid="$(gitscip-shell system . . git. rev-parse HEAD)"
175 expected_commit_msg="run git-lfs migrate import --no-rewrite"
176
177 gitscip-shell system . . git. lfs migrate import --message "$expected_commit_msg" --no-rewrite --yes *.txt
178
179 # Ensure the git history remained the same
180 new_commit_oid="$(gitscip-shell system . . git. rev-parse HEAD~1)"
181 if [scip-shell system . . `[`. "$prev_commit_oid" != "$new_commit_oid" ]; then
182 exit 1
183 fi
184
185 # Ensure a new commit was made
186 new_head_oid="$(gitscip-shell system . . git. rev-parse HEAD)"
187 if [scip-shell system . . `[`. "$prev_commit_oid" == "$new_oid" ]; then
188 exit 1
189 fi
190
191 # Ensure the provided commit message was used
192 commit_msg="$(gitscip-shell system . . git. log -1 --pretty=format:%s)"
193 if [scip-shell system . . `[`. "$commit_msg" != "$expected_commit_msg" ]; then
194 exit 1
195 fi
196 )
197 end_test
198
199 begin_test "migrate import --no-rewrite (with empty commit message)"
200 (
201 set -e
202
203 setup_local_branch_with_gitattrs
204
205 prev_commit_oid="$(gitscip-shell system . . git. rev-parse HEAD)"
206
207 gitscip-shell system . . git. lfs migrate import -m "" --no-rewrite --yes *.txt
208
209 # Ensure the git history remained the same
210 new_commit_oid="$(gitscip-shell system . . git. rev-parse HEAD~1)"
211 if [scip-shell system . . `[`. "$prev_commit_oid" != "$new_commit_oid" ]; then
212 exit 1
213 fi
214
215 # Ensure a new commit was made
216 new_head_oid="$(gitscip-shell system . . git. rev-parse HEAD)"
217 if [scip-shell system . . `[`. "$prev_commit_oid" == "$new_oid" ]; then
218 exit 1
219 fi
220
221 # Ensure the provided commit message was used
222 commit_msg="$(gitscip-shell system . . git. log -1 --pretty=format:%s)"
223 if [scip-shell system . . `[`. "$commit_msg" != "" ]; then
224 exit 1
225 fi
226 )
227 end_test
228
229 begin_test "migrate import --no-rewrite (strict .gitattributes)"
230 (
231 set -e
232
233 reponame="$(basenamescip-shell system . . basename. "$0" ".sh")-strict-match"
234 clone_repo "$reponame" repo-strict-match
235
236 mkdirscip-shell system . . mkdir. -p major-oak/mainst/.yarn-offline-mirror/
237 mkdirscip-shell system . . mkdir. -p major-oak/major-oak/frontend/.yarn-offline-mirror/
238 foo_contents="foo"
239 foo_oid=$(calc_oid "$foo_contents")
240 bar_contents="bar"
241 bar_oid=$(calc_oid "$bar_contents")
242 printfscip-shell system . . printf. "$foo_contents" > major-oak/mainst/.yarn-offline-mirror/typescript-3.4.3.tgz
243 printfscip-shell system . . printf. "$bar_contents" > major-oak/major-oak/frontend/.yarn-offline-mirror/typescript-2.9.2.tgz
244 gitscip-shell system . . git. add .
245 gitscip-shell system . . git. commit -m 'Initial import'
246
247 catscip-shell system . . cat. >.gitattributes <<EOF
248 major-oak/mainst/.yarn-offline-mirror/typescript-3.4.3.tgz filter=lfs diff=lfs merge=lfs -text
249 major-oak/major-oak/frontend/.yarn-offline-mirror/typescript-2.9.2.tgz filter=lfs diff=lfs merge=lfs -text
250 EOF
251
252 gitscip-shell system . . git. add .
253 gitscip-shell system . . git. commit -m '.gitattributes'
254
255 gitscip-shell system . . git. lfs migrate import --yes --no-rewrite \
256 major-oak/mainst/.yarn-offline-mirror/typescript-3.4.3.tgz \
257 major-oak/major-oak/frontend/.yarn-offline-mirror/typescript-2.9.2.tgz
258
259 assert_pointer "refs/heads/main" "major-oak/mainst/.yarn-offline-mirror/typescript-3.4.3.tgz" "$foo_oid" "3"
260 assert_pointer "refs/heads/main" "major-oak/major-oak/frontend/.yarn-offline-mirror/typescript-2.9.2.tgz" "$bar_oid" "3"
261
262 assert_local_object "$foo_oid" "3"
263 assert_local_object "$bar_oid" "3"
264 )
265 end_test