Skip to content

Commit ac61c17

Browse files
committed
Ignore files within a .git directory
* Do not consider files within a .git directory when we are using separate-weights
1 parent 3ca6205 commit ac61c17

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

pkg/weights/weights.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ func FindWeights(fw FileWalker) ([]string, []string, error) {
3030
if info.IsDir() {
3131
return nil
3232
}
33+
if isGitFile(path) {
34+
return nil
35+
}
3336
if isCodeFile(path) {
3437
codeFiles = append(codeFiles, path)
3538
return nil
@@ -97,6 +100,10 @@ func isCodeFile(path string) bool {
97100
return ext == ".py" || ext == ".ipynb"
98101
}
99102

103+
func isGitFile(path string) bool {
104+
return strings.Contains(path, ".git")
105+
}
106+
100107
// filterDirsContainingCode filters out directories that contain code files.
101108
// If a dir is a prefix for any given codeFiles, it will be filtered out.
102109
func filterDirsContainingCode(dirs []string, codeFiles []string) []string {

pkg/weights/weights_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,3 +160,19 @@ func TestSubDirMerge(t *testing.T) {
160160
require.Empty(t, rootFiles)
161161
require.Equal(t, []string{"models"}, dirs)
162162
}
163+
164+
// Test case for ignoring files within a .git directory
165+
func TestIgnoreGitFiles(t *testing.T) {
166+
mockFileWalker := func(root string, walkFn filepath.WalkFunc) error {
167+
sizes := []int64{sizeThreshold, sizeThreshold, 1024}
168+
for i, path := range []string{".git/root-large", "root-large", "predict.py"} {
169+
walkFn(path, mockFileInfo{size: sizes[i]}, nil)
170+
}
171+
return nil
172+
}
173+
174+
dirs, rootFiles, err := FindWeights(mockFileWalker)
175+
require.NoError(t, err)
176+
require.Equal(t, []string{"root-large"}, rootFiles)
177+
require.Empty(t, dirs)
178+
}

0 commit comments

Comments
 (0)