Skip to content

Commit 4fd2cd7

Browse files
justinsbAdirio
andcommitted
Tolerate "dot" directories when checking if dir is empty
Many users will be running version control; we should ignore .git directories also therefore. We ignore all directories starting with "." (just as we ignore all files starting with "."). Also add go.sum to ignore list, as go.mod is already ignored. Co-authored-by: Adrián <[email protected]>
1 parent 14b27b4 commit 4fd2cd7

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

pkg/plugins/golang/v3/init.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,9 +207,16 @@ func checkDir() error {
207207
if err != nil {
208208
return err
209209
}
210-
if info.Name() != "go.mod" && !strings.HasPrefix(info.Name(), ".") {
210+
// Allow the whole .git directory tree
211+
if info.IsDir() && strings.HasPrefix(info.Name(), ".") && info.Name() != "." {
212+
return filepath.SkipDir
213+
}
214+
// Also allow go.mod and dot-files
215+
if info.Name() != "go.mod" && info.Name() != "go.sum" && !strings.HasPrefix(info.Name(), ".") {
211216
return fmt.Errorf(
212-
"target directory is not empty (only go.mod and files with the prefix \".\" are allowed); found existing file %q",
217+
"target directory is not empty "+
218+
"(only go.mod, go.sum, and files and directories with the prefix \".\" are allowed); "+
219+
"found existing file %q",
213220
path)
214221
}
215222
return nil

0 commit comments

Comments
 (0)