Merge pull request #4697 from bk2204/fsck-misdetection

Fix two types of misdetection in git lfs fsck
This commit is contained in:
brian m. carlson 2021-10-25 12:45:10 +00:00 committed by GitHub
commit d0af7dd084
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 60 additions and 5 deletions

@ -12,6 +12,7 @@ import (
type TreeBlob struct {
Oid string
Size int64
Mode int32
Filename string
}
@ -53,6 +54,11 @@ func (s *LsTreeScanner) next() (*TreeBlob, bool) {
return nil, hasNext
}
mode, err := strconv.ParseInt(strings.TrimSpace(attrs[0]), 8, 32)
if err != nil {
return nil, hasNext
}
if attrs[1] != "blob" {
return nil, hasNext
}
@ -64,7 +70,7 @@ func (s *LsTreeScanner) next() (*TreeBlob, bool) {
oid := attrs[2]
filename := parts[1]
return &TreeBlob{Oid: oid, Size: sz, Filename: filename}, hasNext
return &TreeBlob{Oid: oid, Size: sz, Mode: int32(mode), Filename: filename}, hasNext
}
func scanNullLines(data []byte, atEOF bool) (advance int, token []byte, err error) {

@ -199,19 +199,25 @@ func catFileBatchTreeForPointers(treeblobs *TreeBlobChannelWrapper, gitEnv, osEn
return nil, nil, err
}
patterns := make([]filepathfilter.Pattern, 0, len(paths))
includes := make([]filepathfilter.Pattern, 0, len(paths))
excludes := make([]filepathfilter.Pattern, 0, len(paths))
for _, path := range paths {
// Convert all separators to `/` before creating a pattern to
// avoid characters being escaped in situations like `subtree\*.md`
patterns = append(patterns, filepathfilter.NewPattern(filepath.ToSlash(path.Path), filepathfilter.GitAttributes))
pattern := filepathfilter.NewPattern(filepath.ToSlash(path.Path), filepathfilter.GitAttributes)
if path.Tracked {
includes = append(includes, pattern)
} else {
excludes = append(excludes, pattern)
}
}
return pointers, filepathfilter.NewFromPatterns(patterns, nil, filepathfilter.DefaultValue(false)), nil
return pointers, filepathfilter.NewFromPatterns(includes, excludes, filepathfilter.DefaultValue(false)), nil
}
func runScanTreeForPointers(cb GitScannerFoundPointer, tree string, gitEnv, osEnv config.Environment) error {
treeShas, err := lsTreeBlobs(tree, func(t *git.TreeBlob) bool {
return t != nil
return t != nil && (t.Mode == 0100644 || t.Mode == 0100755)
})
if err != nil {
return err

@ -221,6 +221,49 @@ begin_test "fsck does not detect invalid pointers with no LFS objects"
)
end_test
begin_test "fsck does not detect invalid pointers with symlinks"
(
set -e
reponame="fsck-pointers-symlinks"
git init "$reponame"
cd "$reponame"
git lfs track '*.dat'
echo "# Test" > a.dat
ln -s a.dat b.dat
git add .gitattributes *.dat
git commit -m "Add files"
git lfs fsck
git lfs fsck --pointers
)
end_test
begin_test "fsck does not detect invalid pointers with negated patterns"
(
set -e
reponame="fsck-pointers-none"
git init "$reponame"
cd "$reponame"
cat > .gitattributes <<EOF
*.dat filter=lfs diff=lfs merge=lfs -text
b.dat !filter !diff !merge text
EOF
echo "# Test" > a.dat
cp a.dat b.dat
git add .gitattributes *.dat
git commit -m "Add files"
git lfs fsck
git lfs fsck --pointers
)
end_test
begin_test "fsck operates on specified refs"
(
set -e