diff --git a/commands/command_migrate.go b/commands/command_migrate.go index 5e8f57d7..1db3743b 100644 --- a/commands/command_migrate.go +++ b/commands/command_migrate.go @@ -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() diff --git a/docs/man/git-lfs-migrate.1.ronn b/docs/man/git-lfs-migrate.1.ronn index 3af4fe54..9b06b135 100644 --- a/docs/man/git-lfs-migrate.1.ronn +++ b/docs/man/git-lfs-migrate.1.ronn @@ -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 diff --git a/test/test-migrate-fixtures.sh b/test/test-migrate-fixtures.sh index e628f0af..f45c686b 100755 --- a/test/test-migrate-fixtures.sh +++ b/test/test-migrate-fixtures.sh @@ -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 diff --git a/test/test-migrate-import.sh b/test/test-migrate-import.sh index 22517d0b..da2fe1a5 100755 --- a/test/test-migrate-import.sh +++ b/test/test-migrate-import.sh @@ -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