Skip to content

Commit d263a97

Browse files
authored
Merge pull request git-lfs#3121 from git-lfs/ttaylorr/migrate-everything-loosen
commands/command_migrate.go: loosen meaning of '--everything'
2 parents 1a3327f + 6456aa8 commit d263a97

File tree

4 files changed

+81
-10
lines changed

4 files changed

+81
-10
lines changed

commands/command_migrate.go

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,13 +173,31 @@ func includeExcludeRefs(l *tasklog.Logger, args []string) (include, exclude []st
173173
include = append(include, migrateIncludeRefs...)
174174
exclude = append(exclude, migrateExcludeRefs...)
175175
} else if migrateEverything {
176-
localRefs, err := git.LocalRefs()
176+
refs, err := git.AllRefsIn("")
177177
if err != nil {
178178
return nil, nil, err
179179
}
180180

181-
for _, ref := range localRefs {
182-
include = append(include, ref.Refspec())
181+
for _, ref := range refs {
182+
switch ref.Type {
183+
case git.RefTypeLocalBranch, git.RefTypeLocalTag,
184+
git.RefTypeRemoteBranch, git.RefTypeRemoteTag:
185+
186+
include = append(include, ref.Refspec())
187+
case git.RefTypeOther:
188+
parts := strings.SplitN(ref.Refspec(), "/", 3)
189+
if len(parts) < 2 {
190+
continue
191+
}
192+
193+
switch parts[1] {
194+
// The following are GitLab-, GitHub-, VSTS-,
195+
// and BitBucket-specific reference naming
196+
// conventions.
197+
case "merge-requests", "pull", "pull-requests":
198+
include = append(include, ref.Refspec())
199+
}
200+
}
183201
}
184202
} else {
185203
bare, err := git.IsBare()

docs/man/git-lfs-migrate.1.ronn

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,8 @@ The following configuration:
190190

191191
Would, therefore, include commits: F, E, D, C, B, but exclude commit A.
192192

193-
The presence of flag `--everything` indicates that all local references should be
194-
migrated.
193+
The presence of flag `--everything` indicates that all local and remote
194+
references should be migrated.
195195

196196
## EXAMPLES
197197

@@ -253,16 +253,20 @@ Note: This will require a force push to any existing Git remotes.
253253

254254
### Migrate without rewriting local history
255255

256-
You can also migrate files without modifying the existing history of your respoitory:
256+
You can also migrate files without modifying the existing history of your
257+
repository:
257258

258259
Without a specified commit message:
260+
259261
```
260-
git lfs migrate import --no-rewrite test.zip *.mp3 *.psd
262+
$ git lfs migrate import --no-rewrite test.zip *.mp3 *.psd
261263
```
264+
262265
With a specified commit message:
266+
263267
```
264-
git lfs migrate import --no-rewrite -m "Import .zip, .mp3, .psd files" \
265-
test.zip *.mpd *.psd
268+
$ git lfs migrate import --no-rewrite -m "Import .zip, .mp3, .psd files" \
269+
test.zip *.mpd *.psd
266270
```
267271

268272
## SEE ALSO

test/test-migrate-fixtures.sh

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ setup_single_local_branch_tracked_corrupt() {
178178
#
179179
# - Commit 'A' has 120, 140 bytes of data in a.txt, and a.md, respectively.
180180
#
181-
# - Commit 'B' has 30 bytes of data in a.txt, and includes commit 'A' as a
181+
# - Commit 'B' has 30 bytes of data in a.md, and includes commit 'A' as a
182182
# parent.
183183
setup_multiple_local_branches() {
184184
set -e
@@ -218,6 +218,29 @@ setup_multiple_local_branches_with_gitattrs() {
218218
git commit -m "add .gitattributes"
219219
}
220220

221+
# setup_multiple_local_branches_non_standard creates a repository as follows:
222+
#
223+
# refs/pull/1/head
224+
# /
225+
# |
226+
# B
227+
# / \
228+
# A refs/heads/my-feature
229+
# |\
230+
# | refs/heads/master
231+
# \
232+
# refs/pull/1/base
233+
#
234+
# With the same contents in 'A' and 'B' as setup_multiple_local_branches.
235+
setup_multiple_local_branches_non_standard() {
236+
set -e
237+
238+
setup_multiple_local_branches
239+
240+
git update-ref refs/pull/1/head "$(git rev-parse my-feature)"
241+
git update-ref refs/pull/1/base "$(git rev-parse master)"
242+
}
243+
221244
# setup_multiple_local_branches_tracked creates a repo with exactly the same
222245
# structure as in setup_multiple_local_branches, but with all files tracked by
223246
# Git LFS

test/test-migrate-import.sh

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -707,3 +707,29 @@ begin_test "migrate import (multiple remotes)"
707707
assert_ref_unmoved "master" "$original_master" "$migrated_master"
708708
)
709709
end_test
710+
711+
begin_test "migrate import (non-standard refs)"
712+
(
713+
set -e
714+
715+
setup_multiple_local_branches_non_standard
716+
717+
md_oid="$(calc_oid "$(git cat-file -p :a.md)")"
718+
txt_oid="$(calc_oid "$(git cat-file -p :a.txt)")"
719+
md_feature_oid="$(calc_oid "$(git cat-file -p my-feature:a.md)")"
720+
721+
git lfs migrate import --everything
722+
723+
assert_pointer "refs/heads/master" "a.md" "$md_oid" "140"
724+
assert_pointer "refs/heads/master" "a.txt" "$txt_oid" "120"
725+
assert_pointer "refs/pull/1/base" "a.md" "$md_oid" "140"
726+
assert_pointer "refs/pull/1/base" "a.txt" "$txt_oid" "120"
727+
728+
assert_pointer "refs/heads/my-feature" "a.txt" "$txt_oid" "120"
729+
assert_pointer "refs/pull/1/head" "a.txt" "$txt_oid" "120"
730+
731+
assert_local_object "$md_oid" "140"
732+
assert_local_object "$txt_oid" "120"
733+
assert_local_object "$md_feature_oid" "30"
734+
)
735+
end_test

0 commit comments

Comments
 (0)