File: t-migrate-import-no-rewrite.sh

package info (click to toggle)
git-lfs 3.6.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 4,808 kB
  • sloc: sh: 21,256; makefile: 507; ruby: 417
file content (265 lines) | stat: -rwxr-xr-x 7,671 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
#!/usr/bin/env bash

. "$(dirname "$0")/fixtures/migrate.sh"
. "$(dirname "$0")/testlib.sh"

begin_test "migrate import --no-rewrite (default branch)"
(
  set -e

  setup_local_branch_with_gitattrs

  txt_oid="$(calc_oid "$(git cat-file -p :a.txt)")"
  prev_commit_oid="$(git rev-parse HEAD)"

  git lfs migrate import --no-rewrite --yes *.txt

  # Ensure our desired files were imported into git-lfs
  assert_pointer "refs/heads/main" "a.txt" "$txt_oid" "120"
  assert_local_object "$txt_oid" "120"

  # Ensure the git history remained the same
  new_commit_oid="$(git rev-parse HEAD~1)"
  if [ "$prev_commit_oid" != "$new_commit_oid" ]; then
    exit 1
  fi

  # Ensure a new commit was made
  new_head_oid="$(git rev-parse HEAD)"
  if [ "$prev_commit_oid" == "$new_oid" ]; then
    exit 1
  fi

  # Ensure a new commit message was generated based on the list of imported files
  commit_msg="$(git log -1 --pretty=format:%s)"
  echo "$commit_msg" | grep -q "a.txt: convert to Git LFS"

  # Ensure we write a valid commit object.
  git fsck
)
end_test

begin_test "migrate import --no-rewrite (bare repository)"
(
  set -e

  setup_single_remote_branch_with_gitattrs

  prev_commit_oid="$(git rev-parse HEAD)"
  txt_oid="$(calc_oid "$(git cat-file -p :a.txt)")"
  md_oid="$(calc_oid "$(git cat-file -p :a.md)")"

  git lfs migrate import --no-rewrite --yes a.txt a.md

  # Ensure our desired files were imported
  assert_pointer "refs/heads/main" "a.txt" "$txt_oid" "30"
  assert_pointer "refs/heads/main" "a.md" "$md_oid" "50"

  # Ensure the git history remained the same
  new_commit_oid="$(git rev-parse HEAD~1)"
  if [ "$prev_commit_oid" != "$new_commit_oid" ]; then
    exit 1
  fi

  # Ensure a new commit was made
  new_head_oid="$(git rev-parse HEAD)"
  if [ "$prev_commit_oid" == "$new_oid" ]; then
    exit 1
  fi
)
end_test

begin_test "migrate import --no-rewrite (multiple branches)"
(
  set -e

  setup_multiple_local_branches_with_gitattrs

  prev_commit_oid="$(git rev-parse HEAD)"

  md_oid="$(calc_oid "$(git cat-file -p :a.md)")"
  txt_oid="$(calc_oid "$(git cat-file -p :a.txt)")"
  md_feature_oid="$(calc_oid "$(git cat-file -p my-feature:a.md)")"

  git lfs migrate import --no-rewrite --yes *.txt *.md

  # Ensure our desired files were imported
  assert_pointer "refs/heads/main" "a.md" "$md_oid" "140"
  assert_pointer "refs/heads/main" "a.txt" "$txt_oid" "120"

  assert_local_object "$md_oid" "140"
  assert_local_object "$txt_oid" "120"

  # Ensure our other branch was unmodified
  refute_local_object "$md_feature_oid" "30"

  # Ensure the git history remained the same
  new_commit_oid="$(git rev-parse HEAD~1)"
  if [ "$prev_commit_oid" != "$new_commit_oid" ]; then
    exit 1
  fi

  # Ensure a new commit was made
  new_head_oid="$(git rev-parse HEAD)"
  if [ "$prev_commit_oid" == "$new_oid" ]; then
    exit 1
  fi
)
end_test

begin_test "migrate import --no-rewrite (no .gitattributes)"
(
  set -e

  setup_multiple_local_branches

  # Ensure command fails if no .gitattributes files are present
  git lfs migrate import --no-rewrite --yes *.txt *.md 2>&1 | tee migrate.log
  if [ ${PIPESTATUS[0]} -eq 0 ]; then
    echo >&2 "Expected git lfs migrate import --no-rewrite to fail, didn't"
    exit 1
  fi

  grep "No Git LFS filters found in '.gitattributes'" migrate.log
)
end_test

begin_test "migrate import --no-rewrite (nested .gitattributes)"
(
  set -e

  setup_local_branch_with_nested_gitattrs

  # Ensure a .md filter does not exist in the top-level .gitattributes
  main_attrs="$(git cat-file -p "$main:.gitattributes")"
  echo "$main_attrs" | grep -q ".md" && exit 1

  # Ensure a .md filter exists in the nested .gitattributes
  nested_attrs="$(git cat-file -p "$main:b/.gitattributes")"
  echo "$nested_attrs" | grep -q "*.md filter=lfs diff=lfs merge=lfs"

  md_oid="$(calc_oid "$(git cat-file -p :a.md)")"
  nested_md_oid="$(calc_oid "$(git cat-file -p :b/a.md)")"
  txt_oid="$(calc_oid "$(git cat-file -p :a.txt)")"

  git lfs migrate import --no-rewrite --yes a.txt b/a.md

  # Ensure a.txt and subtree/a.md were imported, even though *.md only exists in the
  # nested subtree/.gitattributes file
  assert_pointer "refs/heads/main" "b/a.md" "$nested_md_oid" "140"
  assert_pointer "refs/heads/main" "a.txt" "$txt_oid" "120"

  assert_local_object "$nested_md_oid" 140
  assert_local_object "$txt_oid" 120
  refute_local_object "$md_oid" 140

  # Failure should occur when trying to import a.md as no entry exists in
  # top-level .gitattributes file
  git lfs migrate import --no-rewrite --yes a.md 2>&1 | tee migrate.log
  if [ ${PIPESTATUS[0]} -eq 0 ]; then
    echo >&2 "Expected git lfs migrate import --no-rewrite to fail, didn't"
    exit 1
  fi

  grep "a.md did not match any Git LFS filters in '.gitattributes'" migrate.log
)
end_test

begin_test "migrate import --no-rewrite (with commit message)"
(
  set -e

  setup_local_branch_with_gitattrs

  prev_commit_oid="$(git rev-parse HEAD)"
  expected_commit_msg="run git-lfs migrate import --no-rewrite"

  git lfs migrate import --message "$expected_commit_msg" --no-rewrite --yes *.txt

  # Ensure the git history remained the same
  new_commit_oid="$(git rev-parse HEAD~1)"
  if [ "$prev_commit_oid" != "$new_commit_oid" ]; then
    exit 1
  fi

  # Ensure a new commit was made
  new_head_oid="$(git rev-parse HEAD)"
  if [ "$prev_commit_oid" == "$new_oid" ]; then
    exit 1
  fi

  # Ensure the provided commit message was used
  commit_msg="$(git log -1 --pretty=format:%s)"
  if [ "$commit_msg" != "$expected_commit_msg" ]; then
    exit 1
  fi
)
end_test

begin_test "migrate import --no-rewrite (with empty commit message)"
(
  set -e

  setup_local_branch_with_gitattrs

  prev_commit_oid="$(git rev-parse HEAD)"

  git lfs migrate import -m "" --no-rewrite --yes *.txt

  # Ensure the git history remained the same
  new_commit_oid="$(git rev-parse HEAD~1)"
  if [ "$prev_commit_oid" != "$new_commit_oid" ]; then
    exit 1
  fi

  # Ensure a new commit was made
  new_head_oid="$(git rev-parse HEAD)"
  if [ "$prev_commit_oid" == "$new_oid" ]; then
    exit 1
  fi

  # Ensure the provided commit message was used
  commit_msg="$(git log -1 --pretty=format:%s)"
  if [ "$commit_msg" != "" ]; then
    exit 1
  fi
)
end_test

begin_test "migrate import --no-rewrite (strict .gitattributes)"
(
  set -e

  reponame="$(basename "$0" ".sh")-strict-match"
  clone_repo "$reponame" repo-strict-match

  mkdir -p major-oak/mainst/.yarn-offline-mirror/
  mkdir -p major-oak/major-oak/frontend/.yarn-offline-mirror/
  foo_contents="foo"
  foo_oid=$(calc_oid "$foo_contents")
  bar_contents="bar"
  bar_oid=$(calc_oid "$bar_contents")
  printf "$foo_contents" > major-oak/mainst/.yarn-offline-mirror/typescript-3.4.3.tgz
  printf "$bar_contents" > major-oak/major-oak/frontend/.yarn-offline-mirror/typescript-2.9.2.tgz
  git add .
  git commit -m 'Initial import'

  cat >.gitattributes <<EOF
major-oak/mainst/.yarn-offline-mirror/typescript-3.4.3.tgz filter=lfs diff=lfs merge=lfs -text
major-oak/major-oak/frontend/.yarn-offline-mirror/typescript-2.9.2.tgz filter=lfs diff=lfs merge=lfs -text
EOF

  git add .
  git commit -m '.gitattributes'

  git lfs migrate import --yes --no-rewrite \
    major-oak/mainst/.yarn-offline-mirror/typescript-3.4.3.tgz \
    major-oak/major-oak/frontend/.yarn-offline-mirror/typescript-2.9.2.tgz

  assert_pointer "refs/heads/main" "major-oak/mainst/.yarn-offline-mirror/typescript-3.4.3.tgz" "$foo_oid" "3"
  assert_pointer "refs/heads/main" "major-oak/major-oak/frontend/.yarn-offline-mirror/typescript-2.9.2.tgz" "$bar_oid" "3"

  assert_local_object "$foo_oid" "3"
  assert_local_object "$bar_oid" "3"
)
end_test