From a895def2ae901546c50a4a82f4de54f67d5f56c1 Mon Sep 17 00:00:00 2001 From: Chris Darroch Date: Mon, 3 May 2021 11:22:09 -0700 Subject: [PATCH] commands,docs,t: change default info pointer mode Use the new "follow" mode by default when running the "git lfs migrate info" command, since we can break with backwards compatibility for a Git LFS 3.0 release. --- commands/command_migrate_info.go | 6 +-- docs/man/git-lfs-migrate.1.ronn | 46 ++++++++++---------- t/t-migrate-info.sh | 74 ++++++++++++-------------------- 3 files changed, 52 insertions(+), 74 deletions(-) diff --git a/commands/command_migrate_info.go b/commands/command_migrate_info.go index caced24a..6ca2722a 100644 --- a/commands/command_migrate_info.go +++ b/commands/command_migrate_info.go @@ -21,8 +21,8 @@ import ( type migrateInfoPointersType int const ( - migrateInfoPointersNoFollow = migrateInfoPointersType(iota) migrateInfoPointersFollow = migrateInfoPointersType(iota) + migrateInfoPointersNoFollow = migrateInfoPointersType(iota) migrateInfoPointersIgnore = migrateInfoPointersType(iota) ) @@ -86,10 +86,10 @@ func migrateInfoCommand(cmd *cobra.Command, args []string) { if pointers := cmd.Flag("pointers"); pointers.Changed { switch pointers.Value.String() { - case "no-follow": - migrateInfoPointersMode = migrateInfoPointersNoFollow case "follow": migrateInfoPointersMode = migrateInfoPointersFollow + case "no-follow": + migrateInfoPointersMode = migrateInfoPointersNoFollow case "ignore": migrateInfoPointersMode = migrateInfoPointersIgnore default: diff --git a/docs/man/git-lfs-migrate.1.ronn b/docs/man/git-lfs-migrate.1.ronn index 1959e0f0..ab0f9858 100644 --- a/docs/man/git-lfs-migrate.1.ronn +++ b/docs/man/git-lfs-migrate.1.ronn @@ -81,12 +81,11 @@ like the other two modes, by default the `info` mode operates only on the currently checked-out branch and only on commits which do not exist on any remote, so to get a summary of the entire repository across all branches, use the `--everything` option. If objects have already been converted to -Git LFS pointers, then by default the size of the pointers is totaled, not -the size of the Git LFS objects to which they refer. This is done to retain -compatability with previous versions of Git LFS. However, if you have already -have Git LFS objects in your repository, it may be preferable to either -ignore them by using `--pointers=ignore` or report them separately using -`--pointers=follow`. +Git LFS pointers, then by default the size of the referenced objects is +totaled and reported separately. You may also choose to ignore them by +using `--pointers=ignore` or to treat the pointers as files by using +`--pointers=no-follow`. (The latter option is akin to how existing Git LFS +pointers were handled by the `info` mode in prior versions of Git LFS). When using the `--everything` option, take note that it means all refs (local and remote) will be considered, but not necessarily all file types. @@ -174,9 +173,9 @@ It supports all the core `migrate` options and these additional ones: * `--top=` Only display the top `n` entries, ordered by how many total files match the given pathspec. The default is to show only the top 5 entries. When - `--pointers=follow` is specified and existing Git LFS objects are found, - an extra, separate "LFS Objects" line is output in addition to the top - `n` entries. + existing Git LFS objects are found, an extra, separate "LFS Objects" line + is output in addition to the top `n` entries, unless the `--pointers` + option is used to change this behavior. * `--unit=` Format the number of bytes in each entry as a quantity of the storage unit @@ -187,17 +186,16 @@ It supports all the core `migrate` options and these additional ones: If a `--unit` is not specified, the largest unit that can fit the number of counted bytes as a whole number quantity is chosen. -* `--pointers=[no-follow|follow|ignore]` +* `--pointers=[follow|no-follow|ignore]` Treat existing Git LFS pointers in the history according to one of three - alternatives. In the `no-follow` mode, Git LFS pointers are treated as if - they were regular files, so the contents of the pointers themselves are - reported in the output totals, rather than the contents of the Git LFS - objects to which they refer. This is the default when `--pointers` is not - specified, to maintain backwards consistency; however, the other modes may - be more intuitive. The `ignore` mode excludes all Git LFS pointers from - the output totals, while the `follow` mode outputs an additional separate - "LFS Objects" line item which summarizes the total number and size of the - Git LFS objects referenced by pointers. + alternatives. In the default `follow` case, if any pointers are found, + an additional separate "LFS Objects" line item is output which summarizes + the total number and size of the Git LFS objects referenced by pointers. + In the `ignore` case, any pointers are simply ignored, while the `no-follow` + case replicates the behavior of the `info` mode in older Git LFS versions + and treats any pointers it finds as if they were regular files, so the + output totals only include the contents of the pointers, not the contents + of the objects to which they refer. The format of the output shows the filename pattern, the total size of the file objects (excluding those below the `--above` threshold, if one was @@ -388,15 +386,15 @@ migrate: Updating refs: ..., done You can also migrate the entire history of your repository: ``` -# Check for large files in your local main branch +# Check for large files and existing Git LFS objects in your local main branch $ git lfs migrate info --include-ref=main -# Check for large files in every branch +# Check for large files and existing Git LFS objects in every branch $ git lfs migrate info --everything -# Check for large files in every branch, counting existing Git LFS objects -# separately, and listing the top 100 or fewer results -$ git lfs migrate info --everything --pointers=follow --top=100 +# Check for large files in every branch, ignoring any existing Git LFS objects, +# and listing the top 100 or fewer results +$ git lfs migrate info --everything --pointers=ignore --top=100 ``` The same flags will work in `import` mode: diff --git a/t/t-migrate-info.sh b/t/t-migrate-info.sh index 9367111a..dce055c6 100755 --- a/t/t-migrate-info.sh +++ b/t/t-migrate-info.sh @@ -19,16 +19,6 @@ begin_test "migrate info (default branch)" migrated_head="$(git rev-parse HEAD)" assert_ref_unmoved "HEAD" "$original_head" "$migrated_head" - - # Ensure "follow" command reports no objects if no files are tracked by LFS. - diff -u <(git lfs migrate info --pointers=follow 2>&1 | tail -n 2) <(cat <<-EOF - *.md 140 B 1/1 files(s) 100% - *.txt 120 B 1/1 files(s) 100% - EOF) - - migrated_head="$(git rev-parse HEAD)" - - assert_ref_unmoved "HEAD" "$original_head" "$migrated_head" ) end_test @@ -452,9 +442,11 @@ begin_test "migrate info (all files tracked)" original_head="$(git rev-parse HEAD)" - # Ensure "ignore" command reports no objects if all files are tracked by LFS. - diff -u <(git lfs migrate info --pointers=ignore 2>&1 | tail -n 1) <(cat <<-EOF - *.gitattributes 83 B 1/1 files(s) 100% + # Ensure default command reports objects if all files are tracked by LFS. + diff -u <(git lfs migrate info 2>&1 | tail -n 3) <(cat <<-EOF + *.gitattributes 83 B 1/1 files(s) 100% + + LFS Objects 260 B 2/2 files(s) 100% EOF) migrated_head="$(git rev-parse HEAD)" @@ -483,11 +475,9 @@ begin_test "migrate info (all files tracked)" assert_ref_unmoved "HEAD" "$original_head" "$migrated_head" - # Ensure default command reports pointers if all files are tracked by LFS. - diff -u <(git lfs migrate info 2>&1 | tail -n 3) <(cat <<-EOF - *.md 128 B 1/1 files(s) 100% - *.txt 128 B 1/1 files(s) 100% - *.gitattributes 83 B 1/1 files(s) 100% + # Ensure "ignore" command reports no objects if all files are tracked by LFS. + diff -u <(git lfs migrate info --pointers=ignore 2>&1 | tail -n 1) <(cat <<-EOF + *.gitattributes 83 B 1/1 files(s) 100% EOF) migrated_head="$(git rev-parse HEAD)" @@ -505,19 +495,8 @@ begin_test "migrate info (--everything, all files tracked)" original_main="$(git rev-parse refs/heads/main)" original_feature="$(git rev-parse refs/heads/my-feature)" - # Ensure "ignore" command reports no objects if all files are tracked by LFS. - diff -u <(git lfs migrate info --everything --pointers=ignore 2>&1 | tail -n 1) <(cat <<-EOF - *.gitattributes 83 B 1/1 files(s) 100% - EOF) - - migrated_main="$(git rev-parse refs/heads/main)" - migrated_feature="$(git rev-parse refs/heads/my-feature)" - - assert_ref_unmoved "refs/heads/main" "$original_main" "$migrated_main" - assert_ref_unmoved "refs/heads/my-feature" "$original_feature" "$migrated_feature" - - # Ensure "follow" command reports objects if all files are tracked by LFS. - diff -u <(git lfs migrate info --everything --pointers=follow 2>&1 | tail -n 3) <(cat <<-EOF + # Ensure default command reports objects if all files are tracked by LFS. + diff -u <(git lfs migrate info --everything 2>&1 | tail -n 3) <(cat <<-EOF *.gitattributes 83 B 1/1 files(s) 100% LFS Objects 290 B 3/3 files(s) 100% @@ -529,9 +508,9 @@ begin_test "migrate info (--everything, all files tracked)" assert_ref_unmoved "refs/heads/main" "$original_main" "$migrated_main" assert_ref_unmoved "refs/heads/my-feature" "$original_feature" "$migrated_feature" - # Ensure default command reports pointers if all files are tracked by LFS. - diff -u <(git lfs migrate info 2>&1 | tail -n 3) <(cat <<-EOF - *.md 128 B 1/1 files(s) 100% + # Ensure "no-follow" command reports pointers if all files are tracked by LFS. + diff -u <(git lfs migrate info --everything --pointers=no-follow 2>&1 | tail -n 3) <(cat <<-EOF + *.md 255 B 2/2 files(s) 100% *.txt 128 B 1/1 files(s) 100% *.gitattributes 83 B 1/1 files(s) 100% EOF) @@ -541,6 +520,18 @@ begin_test "migrate info (--everything, all files tracked)" assert_ref_unmoved "refs/heads/main" "$original_main" "$migrated_main" assert_ref_unmoved "refs/heads/my-feature" "$original_feature" "$migrated_feature" + + # Ensure "ignore" command reports no objects if all files are tracked by LFS. + diff -u <(git lfs migrate info --everything --pointers=ignore 2>&1 | tail -n 1) <(cat <<-EOF + *.gitattributes 83 B 1/1 files(s) 100% + EOF) + + migrated_main="$(git rev-parse refs/heads/main)" + migrated_feature="$(git rev-parse refs/heads/my-feature)" + + assert_ref_unmoved "refs/heads/main" "$original_main" "$migrated_main" + assert_ref_unmoved "refs/heads/my-feature" "$original_feature" "$migrated_feature" + ) end_test @@ -552,19 +543,8 @@ begin_test "migrate info (potential fixup)" original_head="$(git rev-parse HEAD)" - # Ensure "follow" command reports no objects for files which should be - # tracked but have not been stored properly as LFS pointers. - diff -u <(git lfs migrate info --pointers=follow 2>&1 | tail -n 2) <(cat <<-EOF - *.txt 120 B 1/1 files(s) 100% - *.gitattributes 42 B 1/1 files(s) 100% - EOF) - - migrated_head="$(git rev-parse HEAD)" - - assert_ref_unmoved "HEAD" "$original_head" "$migrated_head" - - # Ensure default command reports files which should be tracked but have not - # been stored properly as LFS pointers. + # Ensure command reports files which should be tracked but have not been + # stored properly as LFS pointers. diff -u <(git lfs migrate info 2>&1 | tail -n 2) <(cat <<-EOF *.txt 120 B 1/1 files(s) 100% *.gitattributes 42 B 1/1 files(s) 100%