Merge branch 'main' into extra-git-string-translations

This commit is contained in:
Chris Darroch 2022-01-31 11:41:17 -08:00
commit a483a87ed2
9 changed files with 186 additions and 9 deletions

@ -196,7 +196,6 @@ func migrateImportCommand(cmd *cobra.Command, args []string) {
if err != nil { if err != nil {
return err return err
} }
return nil
} }
return nil return nil
}, },
@ -322,8 +321,12 @@ func trackedFromAttrs(db *gitobj.ObjectDatabase, t *gitobj.Tree) (*tools.Ordered
for _, e := range t.Entries { for _, e := range t.Entries {
if strings.ToLower(e.Name) == ".gitattributes" && e.Type() == gitobj.BlobObjectType { if strings.ToLower(e.Name) == ".gitattributes" && e.Type() == gitobj.BlobObjectType {
oid = e.Oid if e.IsLink() {
break return nil, errors.Errorf("migrate: %s", tr.Tr.Get("expected '.gitattributes' to be a file, got a symbolic link"))
} else {
oid = e.Oid
break
}
} }
} }

@ -164,15 +164,28 @@ func migrateInfoCommand(cmd *cobra.Command, args []string) {
}, },
TreePreCallbackFn: func(path string, t *gitobj.Tree) error { TreePreCallbackFn: func(path string, t *gitobj.Tree) error {
if migrateFixup && path == "/" { if migrateFixup {
var err error if path == "/" {
var err error
fixups, err = gitattr.New(db, t) fixups, err = gitattr.New(db, t)
if err != nil { if err != nil {
return err return err
}
} }
return nil return nil
} }
for _, e := range t.Entries {
if strings.ToLower(e.Name) == ".gitattributes" && e.Type() == gitobj.BlobObjectType {
if e.IsLink() {
return errors.Errorf("migrate: %s", tr.Tr.Get("expected '.gitattributes' to be a file, got a symbolic link"))
} else {
break
}
}
}
return nil return nil
}, },
}) })

@ -53,7 +53,9 @@ in [INCLUDE AND EXCLUDE].
As typical Git LFS usage depends on tracking specific file types using As typical Git LFS usage depends on tracking specific file types using
filename patterns defined in `.gitattributes` files, the `git lfs migrate` filename patterns defined in `.gitattributes` files, the `git lfs migrate`
command will examine, create, and modify `.gitattributes` files as command will examine, create, and modify `.gitattributes` files as
necessary. necessary. The `.gitattributes` files will always be assigned the default
read/write permissions mode (i.e., without execute permissions). Any
symbolic links with that name will cause the migration to halt prematurely.
The `import` mode (see [IMPORT]) will convert Git objects of the file types The `import` mode (see [IMPORT]) will convert Git objects of the file types
specified (e.g., with `--include`) to Git LFS pointers, and will add entries specified (e.g., with `--include`) to Git LFS pointers, and will add entries

@ -3,6 +3,8 @@ package gitattr
import ( import (
"strings" "strings"
"github.com/git-lfs/git-lfs/v3/errors"
"github.com/git-lfs/git-lfs/v3/tr"
"github.com/git-lfs/gitobj/v2" "github.com/git-lfs/gitobj/v2"
) )
@ -63,6 +65,9 @@ func linesInTree(db *gitobj.ObjectDatabase, t *gitobj.Tree) ([]*Line, string, er
var at int = -1 var at int = -1
for i, e := range t.Entries { for i, e := range t.Entries {
if e.Name == ".gitattributes" { if e.Name == ".gitattributes" {
if e.IsLink() {
return nil, "", errors.Errorf("migrate: %s", tr.Tr.Get("expected '.gitattributes' to be a file, got a symbolic link"))
}
at = i at = i
break break
} }

@ -28,6 +28,8 @@ assert_ref_unmoved() {
# #
# If "0755" is passed as an argument, the .gitattributes file is created # If "0755" is passed as an argument, the .gitattributes file is created
# with that permissions mode. # with that permissions mode.
# If "link" is passed as an argument, the .gitattributes file is created
# as a symlink to a gitattrs file.
setup_local_branch_with_gitattrs() { setup_local_branch_with_gitattrs() {
set -e set -e
@ -45,6 +47,12 @@ setup_local_branch_with_gitattrs() {
if [[ $1 == "0755" ]]; then if [[ $1 == "0755" ]]; then
chmod +x .gitattributes chmod +x .gitattributes
elif [[ $1 == "link" ]]; then
mv .gitattributes gitattrs
add_symlink gitattrs .gitattributes
git add gitattrs
fi fi
git add .gitattributes git add .gitattributes
@ -128,6 +136,8 @@ setup_single_local_branch_untracked() {
# #
# If "0755" is passed as an argument, the .gitattributes file is created # If "0755" is passed as an argument, the .gitattributes file is created
# with that permissions mode. # with that permissions mode.
# If "link" is passed as an argument, the .gitattributes file is created
# as a symlink to a gitattrs file.
setup_single_local_branch_tracked() { setup_single_local_branch_tracked() {
set -e set -e
@ -150,6 +160,14 @@ setup_single_local_branch_tracked() {
git add a.txt a.md git add a.txt a.md
git commit -m "add a.{txt,md}" git commit -m "add a.{txt,md}"
if [[ $1 == "link" ]]; then
git mv .gitattributes gitattrs
add_symlink gitattrs .gitattributes
git commit -m "link .gitattributes"
fi
} }
# setup_single_local_branch_complex_tracked creates a repository as follows: # setup_single_local_branch_complex_tracked creates a repository as follows:
@ -191,6 +209,9 @@ setup_single_local_branch_complex_tracked() {
# #
# - Commit 'A' has 120 bytes of random data in a.txt, and tracks *.txt under Git # - Commit 'A' has 120 bytes of random data in a.txt, and tracks *.txt under Git
# LFS, but a.txt is not stored as an LFS object. # LFS, but a.txt is not stored as an LFS object.
#
# If "link" is passed as an argument, the .gitattributes file is created
# as a symlink to a gitattrs file.
setup_single_local_branch_tracked_corrupt() { setup_single_local_branch_tracked_corrupt() {
set -e set -e
@ -203,6 +224,14 @@ setup_single_local_branch_tracked_corrupt() {
base64 < /dev/urandom | head -c 120 > a.txt base64 < /dev/urandom | head -c 120 > a.txt
if [[ $1 == "link" ]]; then
mv .gitattributes gitattrs
add_symlink gitattrs .gitattributes
git add .gitattributes
fi
git add .gitattributes a.txt git add .gitattributes a.txt
git commit -m "initial commit" git commit -m "initial commit"

@ -413,6 +413,31 @@ EOF
) )
end_test end_test
begin_test "migrate export (.gitattributes symlink)"
(
set -e
setup_single_local_branch_tracked link
git lfs migrate export --yes --include="*.txt" 2>&1 | tee migrate.log
if [ ${PIPESTATUS[0]} -eq 0 ]; then
echo >&2 "fatal: expected git lfs migrate export to fail, didn't"
exit 1
fi
grep "migrate: expected '.gitattributes' to be a file, got a symbolic link" migrate.log
main="$(git rev-parse refs/heads/main)"
attrs_main_sha="$(git show $main:.gitattributes | git hash-object --stdin)"
diff -u <(git ls-tree $main -- .gitattributes) <(cat <<-EOF
120000 blob $attrs_main_sha .gitattributes
EOF
)
)
end_test
begin_test "migrate export (--object-map)" begin_test "migrate export (--object-map)"
( (
set -e set -e

@ -129,3 +129,28 @@ begin_test "migrate import (--fixup with remote tags)"
git lfs migrate import --fixup --yes main git lfs migrate import --fixup --yes main
) )
end_test end_test
begin_test "migrate import (--fixup, .gitattributes symlink)"
(
set -e
setup_single_local_branch_tracked_corrupt link
git lfs migrate import --everything --fixup --yes 2>&1 | tee migrate.log
if [ ${PIPESTATUS[0]} -eq 0 ]; then
echo >&2 "fatal: expected git lfs migrate import to fail, didn't"
exit 1
fi
grep "migrate: expected '.gitattributes' to be a file, got a symbolic link" migrate.log
main="$(git rev-parse refs/heads/main)"
attrs_main_sha="$(git show $main:.gitattributes | git hash-object --stdin)"
diff -u <(git ls-tree $main -- .gitattributes) <(cat <<-EOF
120000 blob $attrs_main_sha .gitattributes
EOF
)
)
end_test

@ -606,6 +606,31 @@ EOF
) )
end_test end_test
begin_test "migrate import (existing .gitattributes symlink)"
(
set -e
setup_local_branch_with_gitattrs link
git lfs migrate import --yes --include-ref=refs/heads/main --include="*.txt" 2>&1 | tee migrate.log
if [ ${PIPESTATUS[0]} -eq 0 ]; then
echo >&2 "fatal: expected git lfs migrate import to fail, didn't"
exit 1
fi
grep "migrate: expected '.gitattributes' to be a file, got a symbolic link" migrate.log
main="$(git rev-parse refs/heads/main)"
attrs_main_sha="$(git show $main:.gitattributes | git hash-object --stdin)"
diff -u <(git ls-tree $main -- .gitattributes) <(cat <<-EOF
120000 blob $attrs_main_sha .gitattributes
EOF
)
)
end_test
begin_test "migrate import (identical contents, different permissions)" begin_test "migrate import (identical contents, different permissions)"
( (
set -e set -e

@ -432,6 +432,56 @@ begin_test "migrate info (--everything)"
) )
end_test end_test
begin_test "migrate info (existing .gitattributes symlink)"
(
set -e
setup_local_branch_with_gitattrs link
git lfs migrate info --everything 2>&1 | tee migrate.log
if [ ${PIPESTATUS[0]} -eq 0 ]; then
echo >&2 "fatal: expected git lfs migrate info to fail, didn't"
exit 1
fi
grep "migrate: expected '.gitattributes' to be a file, got a symbolic link" migrate.log
main="$(git rev-parse refs/heads/main)"
attrs_main_sha="$(git show $main:.gitattributes | git hash-object --stdin)"
diff -u <(git ls-tree $main -- .gitattributes) <(cat <<-EOF
120000 blob $attrs_main_sha .gitattributes
EOF
)
)
end_test
begin_test "migrate info (potential fixup, --fixup, .gitattributes symlink)"
(
set -e
setup_single_local_branch_tracked_corrupt link
git lfs migrate info 2>&1 | tee migrate.log
if [ ${PIPESTATUS[0]} -eq 0 ]; then
echo >&2 "fatal: expected git lfs migrate info to fail, didn't"
exit 1
fi
grep "migrate: expected '.gitattributes' to be a file, got a symbolic link" migrate.log
main="$(git rev-parse refs/heads/main)"
attrs_main_sha="$(git show $main:.gitattributes | git hash-object --stdin)"
diff -u <(git ls-tree $main -- .gitattributes) <(cat <<-EOF
120000 blob $attrs_main_sha .gitattributes
EOF
)
)
end_test
begin_test "migrate info (--fixup, no .gitattributes)" begin_test "migrate info (--fixup, no .gitattributes)"
( (
set -e set -e