Merge pull request #3121 from git-lfs/ttaylorr/migrate-everything-loosen

commands/command_migrate.go: loosen meaning of '--everything'
This commit is contained in:
Taylor Blau 2018-07-17 11:52:07 -05:00 committed by GitHub
commit d263a97f38
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 81 additions and 10 deletions

@ -173,13 +173,31 @@ func includeExcludeRefs(l *tasklog.Logger, args []string) (include, exclude []st
include = append(include, migrateIncludeRefs...)
exclude = append(exclude, migrateExcludeRefs...)
} else if migrateEverything {
localRefs, err := git.LocalRefs()
refs, err := git.AllRefsIn("")
if err != nil {
return nil, nil, err
}
for _, ref := range localRefs {
include = append(include, ref.Refspec())
for _, ref := range refs {
switch ref.Type {
case git.RefTypeLocalBranch, git.RefTypeLocalTag,
git.RefTypeRemoteBranch, git.RefTypeRemoteTag:
include = append(include, ref.Refspec())
case git.RefTypeOther:
parts := strings.SplitN(ref.Refspec(), "/", 3)
if len(parts) < 2 {
continue
}
switch parts[1] {
// The following are GitLab-, GitHub-, VSTS-,
// and BitBucket-specific reference naming
// conventions.
case "merge-requests", "pull", "pull-requests":
include = append(include, ref.Refspec())
}
}
}
} else {
bare, err := git.IsBare()

@ -190,8 +190,8 @@ The following configuration:
Would, therefore, include commits: F, E, D, C, B, but exclude commit A.
The presence of flag `--everything` indicates that all local references should be
migrated.
The presence of flag `--everything` indicates that all local and remote
references should be migrated.
## EXAMPLES
@ -253,16 +253,20 @@ Note: This will require a force push to any existing Git remotes.
### Migrate without rewriting local history
You can also migrate files without modifying the existing history of your respoitory:
You can also migrate files without modifying the existing history of your
repository:
Without a specified commit message:
```
git lfs migrate import --no-rewrite test.zip *.mp3 *.psd
$ git lfs migrate import --no-rewrite test.zip *.mp3 *.psd
```
With a specified commit message:
```
git lfs migrate import --no-rewrite -m "Import .zip, .mp3, .psd files" \
test.zip *.mpd *.psd
$ git lfs migrate import --no-rewrite -m "Import .zip, .mp3, .psd files" \
test.zip *.mpd *.psd
```
## SEE ALSO

@ -178,7 +178,7 @@ setup_single_local_branch_tracked_corrupt() {
#
# - Commit 'A' has 120, 140 bytes of data in a.txt, and a.md, respectively.
#
# - Commit 'B' has 30 bytes of data in a.txt, and includes commit 'A' as a
# - Commit 'B' has 30 bytes of data in a.md, and includes commit 'A' as a
# parent.
setup_multiple_local_branches() {
set -e
@ -218,6 +218,29 @@ setup_multiple_local_branches_with_gitattrs() {
git commit -m "add .gitattributes"
}
# setup_multiple_local_branches_non_standard creates a repository as follows:
#
# refs/pull/1/head
# /
# |
# B
# / \
# A refs/heads/my-feature
# |\
# | refs/heads/master
# \
# refs/pull/1/base
#
# With the same contents in 'A' and 'B' as setup_multiple_local_branches.
setup_multiple_local_branches_non_standard() {
set -e
setup_multiple_local_branches
git update-ref refs/pull/1/head "$(git rev-parse my-feature)"
git update-ref refs/pull/1/base "$(git rev-parse master)"
}
# setup_multiple_local_branches_tracked creates a repo with exactly the same
# structure as in setup_multiple_local_branches, but with all files tracked by
# Git LFS

@ -707,3 +707,29 @@ begin_test "migrate import (multiple remotes)"
assert_ref_unmoved "master" "$original_master" "$migrated_master"
)
end_test
begin_test "migrate import (non-standard refs)"
(
set -e
setup_multiple_local_branches_non_standard
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 --everything
assert_pointer "refs/heads/master" "a.md" "$md_oid" "140"
assert_pointer "refs/heads/master" "a.txt" "$txt_oid" "120"
assert_pointer "refs/pull/1/base" "a.md" "$md_oid" "140"
assert_pointer "refs/pull/1/base" "a.txt" "$txt_oid" "120"
assert_pointer "refs/heads/my-feature" "a.txt" "$txt_oid" "120"
assert_pointer "refs/pull/1/head" "a.txt" "$txt_oid" "120"
assert_local_object "$md_oid" "140"
assert_local_object "$txt_oid" "120"
assert_local_object "$md_feature_oid" "30"
)
end_test