Skip to content

Commit e222f25

Browse files
authored
Merge pull request #1944 from justinsb/tolerate_git_dir
✨ Tolerate "dot" directories when checking if dir is empty
2 parents 14b27b4 + 4fd2cd7 commit e222f25

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)