From e52f7d16c174776cdd66a15e99215c18c49e6459 Mon Sep 17 00:00:00 2001 From: Taylor Blau Date: Mon, 9 Jul 2018 14:44:25 -0500 Subject: [PATCH 1/5] docs/man/git-lfs-migrate.1.ronn: fix ronn formatting --- docs/man/git-lfs-migrate.1.ronn | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/docs/man/git-lfs-migrate.1.ronn b/docs/man/git-lfs-migrate.1.ronn index 3af4fe54..7f024e8c 100644 --- a/docs/man/git-lfs-migrate.1.ronn +++ b/docs/man/git-lfs-migrate.1.ronn @@ -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 From be411309fd3b04c7b7ad54b29b0fa47a8a1e80e1 Mon Sep 17 00:00:00 2001 From: Taylor Blau Date: Mon, 9 Jul 2018 14:43:26 -0500 Subject: [PATCH 2/5] commands/command_migrate.go: loosen meaning of '--everything' In [1] and [2], callers of the 'git lfs migrate' command were surprised when `--everything` did not migrate over everything, as its name implies. In the documentation, we specified that `--everything` applies only to local references, as the default behavior of 'git lfs migrate' is to never require a force-push unless asked to do so explicitly. --everything sounds dangerous enough that it would imply that a user wants _everything_ in their repository migrated. So, let's loosen the requirement and make it mean that. Alternatively, we could change the meaning of `--everything` in this fashion and replace it with `--everything-local`. We could also introduce `--force`, leave the meaning of `--evrything` unchanged, and only exhibit this behavior with `--everything --force`. Both of these options add too much surface area and complexity for use cases that seem less-common, and/or could be accomplished with clever `git for-each-ref` and `xargs`-ing. [1]: https://github.com/git-lfs/git-lfs/issues/2984 [2]: https://github.com/git-lfs/git-lfs/issues/3118 --- commands/command_migrate.go | 24 +++++++++++++++++++++--- docs/man/git-lfs-migrate.1.ronn | 4 ++-- 2 files changed, 23 insertions(+), 5 deletions(-) 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 7f024e8c..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 From 6c6b13fd5e7bf76f45e5d9aec16c01bd50073fbe Mon Sep 17 00:00:00 2001 From: Taylor Blau Date: Mon, 16 Jul 2018 17:07:57 -0500 Subject: [PATCH 3/5] test/test-migrate-fixtures.sh: s/txt/md --- test/test-migrate-fixtures.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test-migrate-fixtures.sh b/test/test-migrate-fixtures.sh index e628f0af..d87da1f4 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 From e311b20d71401180cbb770b83f5421141fa32bb2 Mon Sep 17 00:00:00 2001 From: Taylor Blau Date: Mon, 16 Jul 2018 17:08:24 -0500 Subject: [PATCH 4/5] test/test-migrate-import.sh: test non-standard refs with --everything --- test/test-migrate-fixtures.sh | 23 +++++++++++++++++++++++ test/test-migrate-import.sh | 26 ++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/test/test-migrate-fixtures.sh b/test/test-migrate-fixtures.sh index d87da1f4..e0807671 100755 --- a/test/test-migrate-fixtures.sh +++ b/test/test-migrate-fixtures.sh @@ -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 --create refs/pull/1/head "$(git rev-parse my-feature)" + git update-ref --create 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 From 6456aa8dabd9051d3f6ca92a78bac197d96ab080 Mon Sep 17 00:00:00 2001 From: Taylor Blau Date: Tue, 17 Jul 2018 11:34:33 -0500 Subject: [PATCH 5/5] test/test-migrate-fixtures.sh: remove invalid '--create' When invoking 'git update-ref', a user needs only give the 'create' option when also invoked with --stdin. Since we are not invoking with --stdin, the meaning of --create is implicitly understood. Instead, let's avoid passing a non-existent option and invoke the command correctly. --- test/test-migrate-fixtures.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/test-migrate-fixtures.sh b/test/test-migrate-fixtures.sh index e0807671..f45c686b 100755 --- a/test/test-migrate-fixtures.sh +++ b/test/test-migrate-fixtures.sh @@ -237,8 +237,8 @@ setup_multiple_local_branches_non_standard() { setup_multiple_local_branches - git update-ref --create refs/pull/1/head "$(git rev-parse my-feature)" - git update-ref --create refs/pull/1/base "$(git rev-parse master)" + 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