Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions pkg/weights/weights.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ func FindWeights(fw FileWalker) ([]string, []string, error) {
if info.IsDir() {
return nil
}
if isGitFile(path) {
return nil
}
if isCodeFile(path) {
codeFiles = append(codeFiles, path)
return nil
Expand Down Expand Up @@ -97,6 +100,10 @@ func isCodeFile(path string) bool {
return ext == ".py" || ext == ".ipynb"
}

func isGitFile(path string) bool {
return strings.Contains(path, ".git")
}

// filterDirsContainingCode filters out directories that contain code files.
// If a dir is a prefix for any given codeFiles, it will be filtered out.
func filterDirsContainingCode(dirs []string, codeFiles []string) []string {
Expand Down
16 changes: 16 additions & 0 deletions pkg/weights/weights_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,3 +160,19 @@ func TestSubDirMerge(t *testing.T) {
require.Empty(t, rootFiles)
require.Equal(t, []string{"models"}, dirs)
}

// Test case for ignoring files within a .git directory
func TestIgnoreGitFiles(t *testing.T) {
mockFileWalker := func(root string, walkFn filepath.WalkFunc) error {
sizes := []int64{sizeThreshold, sizeThreshold, 1024}
for i, path := range []string{".git/root-large", "root-large", "predict.py"} {
walkFn(path, mockFileInfo{size: sizes[i]}, nil)
}
return nil
}

dirs, rootFiles, err := FindWeights(mockFileWalker)
require.NoError(t, err)
require.Equal(t, []string{"root-large"}, rootFiles)
require.Empty(t, dirs)
}
Loading