3 . "$(dirname "$0")/fixtures/migrate.sh"
4 . "$(dirname "$0")/testlib.sh"
6 begin_test "migrate import --no-rewrite (default branch)"
10 setup_local_branch_with_gitattrs
12 txt_oid="$(calc_oid "$(git cat-file -p :a.txt)")"
13 prev_commit_oid="$(git rev-parse HEAD)"
15 git lfs migrate import --no-rewrite --yes *.txt
17 # Ensure our desired files were imported into git-lfs
18 assert_pointer "refs/heads/master" "a.txt" "$txt_oid" "120"
19 assert_local_object "$txt_oid" "120"
21 # Ensure the git history remained the same
22 new_commit_oid="$(git rev-parse HEAD~1)"
23 if [ "$prev_commit_oid" != "$new_commit_oid" ]; then
27 # Ensure a new commit was made
28 new_head_oid="$(git rev-parse HEAD)"
29 if [ "$prev_commit_oid" == "$new_oid" ]; then
33 # Ensure a new commit message was generated based on the list of imported files
34 commit_msg="$(git log -1 --pretty=format:%s)"
35 echo "$commit_msg" | grep -q "a.txt: convert to Git LFS"
39 begin_test "migrate import --no-rewrite (bare repository)"
43 setup_single_remote_branch_with_gitattrs
45 prev_commit_oid="$(git rev-parse HEAD)"
46 txt_oid="$(calc_oid "$(git cat-file -p :a.txt)")"
47 md_oid="$(calc_oid "$(git cat-file -p :a.md)")"
49 git lfs migrate import --no-rewrite --yes a.txt a.md
51 # Ensure our desired files were imported
52 assert_pointer "refs/heads/master" "a.txt" "$txt_oid" "30"
53 assert_pointer "refs/heads/master" "a.md" "$md_oid" "50"
55 # Ensure the git history remained the same
56 new_commit_oid="$(git rev-parse HEAD~1)"
57 if [ "$prev_commit_oid" != "$new_commit_oid" ]; then
61 # Ensure a new commit was made
62 new_head_oid="$(git rev-parse HEAD)"
63 if [ "$prev_commit_oid" == "$new_oid" ]; then
69 begin_test "migrate import --no-rewrite (multiple branches)"
73 setup_multiple_local_branches_with_gitattrs
75 prev_commit_oid="$(git rev-parse HEAD)"
77 md_oid="$(calc_oid "$(git cat-file -p :a.md)")"
78 txt_oid="$(calc_oid "$(git cat-file -p :a.txt)")"
79 md_feature_oid="$(calc_oid "$(git cat-file -p my-feature:a.md)")"
81 git lfs migrate import --no-rewrite --yes *.txt *.md
83 # Ensure our desired files were imported
84 assert_pointer "refs/heads/master" "a.md" "$md_oid" "140"
85 assert_pointer "refs/heads/master" "a.txt" "$txt_oid" "120"
87 assert_local_object "$md_oid" "140"
88 assert_local_object "$txt_oid" "120"
90 # Ensure our other branch was unmodified
91 refute_local_object "$md_feature_oid" "30"
93 # Ensure the git history remained the same
94 new_commit_oid="$(git rev-parse HEAD~1)"
95 if [ "$prev_commit_oid" != "$new_commit_oid" ]; then
99 # Ensure a new commit was made
100 new_head_oid="$(git rev-parse HEAD)"
101 if [ "$prev_commit_oid" == "$new_oid" ]; then
107 begin_test "migrate import --no-rewrite (no .gitattributes)"
111 setup_multiple_local_branches
113 # Ensure command fails if no .gitattributes files are present
114 git lfs migrate import --no-rewrite --yes *.txt *.md 2>&1 | tee migrate.log
115 if [ ${PIPESTATUS[0]} -eq 0 ]; then
116 echo >&2 "fatal: expected git lfs migrate import --no-rewrite to fail, didn't"
120 grep "no Git LFS filters found in .gitattributes" migrate.log
124 begin_test "migrate import --no-rewrite (nested .gitattributes)"
128 setup_local_branch_with_nested_gitattrs
130 # Ensure a .md filter does not exist in the top-level .gitattributes
131 master_attrs="$(git cat-file -p "$master:.gitattributes")"
132 [ !"$(echo "$master_attrs" | grep -q ".md")" ]
134 # Ensure a .md filter exists in the nested .gitattributes
135 nested_attrs="$(git cat-file -p "$master:b/.gitattributes")"
136 echo "$nested_attrs" | grep -q "*.md filter=lfs diff=lfs merge=lfs"
138 md_oid="$(calc_oid "$(git cat-file -p :a.md)")"
139 nested_md_oid="$(calc_oid "$(git cat-file -p :b/a.md)")"
140 txt_oid="$(calc_oid "$(git cat-file -p :a.txt)")"
142 git lfs migrate import --no-rewrite --yes a.txt b/a.md
144 # Ensure a.txt and subtree/a.md were imported, even though *.md only exists in the
145 # nested subtree/.gitattributes file
146 assert_pointer "refs/heads/master" "b/a.md" "$nested_md_oid" "140"
147 assert_pointer "refs/heads/master" "a.txt" "$txt_oid" "120"
149 assert_local_object "$nested_md_oid" 140
150 assert_local_object "$txt_oid" 120
151 refute_local_object "$md_oid" 140
153 # Failure should occur when trying to import a.md as no entry exists in
154 # top-level .gitattributes file
155 git lfs migrate import --no-rewrite --yes a.md 2>&1 | tee migrate.log
156 if [ ${PIPESTATUS[0]} -eq 0 ]; then
157 echo >&2 "fatal: expected git lfs migrate import --no-rewrite to fail, didn't"
161 grep "a.md did not match any Git LFS filters in .gitattributes" migrate.log
165 begin_test "migrate import --no-rewrite (with commit message)"
169 setup_local_branch_with_gitattrs
171 prev_commit_oid="$(git rev-parse HEAD)"
172 expected_commit_msg="run git-lfs migrate import --no-rewrite"
174 git lfs migrate import --message "$expected_commit_msg" --no-rewrite --yes *.txt
176 # Ensure the git history remained the same
177 new_commit_oid="$(git rev-parse HEAD~1)"
178 if [ "$prev_commit_oid" != "$new_commit_oid" ]; then
182 # Ensure a new commit was made
183 new_head_oid="$(git rev-parse HEAD)"
184 if [ "$prev_commit_oid" == "$new_oid" ]; then
188 # Ensure the provided commit message was used
189 commit_msg="$(git log -1 --pretty=format:%s)"
190 if [ "$commit_msg" != "$expected_commit_msg" ]; then
196 begin_test "migrate import --no-rewrite (with empty commit message)"
200 setup_local_branch_with_gitattrs
202 prev_commit_oid="$(git rev-parse HEAD)"
204 git lfs migrate import -m "" --no-rewrite --yes *.txt
206 # Ensure the git history remained the same
207 new_commit_oid="$(git rev-parse HEAD~1)"
208 if [ "$prev_commit_oid" != "$new_commit_oid" ]; then
212 # Ensure a new commit was made
213 new_head_oid="$(git rev-parse HEAD)"
214 if [ "$prev_commit_oid" == "$new_oid" ]; then
218 # Ensure the provided commit message was used
219 commit_msg="$(git log -1 --pretty=format:%s)"
220 if [ "$commit_msg" != "" ]; then