Skip to content

Commit

Permalink
Ignore files within a .git directory
Browse files Browse the repository at this point in the history
* Do not consider files within a .git directory
when we are using separate-weights
  • Loading branch information
8W9aG committed Dec 9, 2024
1 parent 3ca6205 commit ac61c17
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
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)
}

0 comments on commit ac61c17

Please sign in to comment.