Skip to content

Commit

Permalink
Tolerate "dot" directories when checking if dir is empty
Browse files Browse the repository at this point in the history
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 <Adirio@users.noreply.github.com>
  • Loading branch information
justinsb and Adirio committed Jan 29, 2021
1 parent 14b27b4 commit 4fd2cd7
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions pkg/plugins/golang/v3/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,16 @@ func checkDir() error {
if err != nil {
return err
}
if info.Name() != "go.mod" && !strings.HasPrefix(info.Name(), ".") {
// Allow the whole .git directory tree
if info.IsDir() && strings.HasPrefix(info.Name(), ".") && info.Name() != "." {
return filepath.SkipDir
}
// Also allow go.mod and dot-files
if info.Name() != "go.mod" && info.Name() != "go.sum" && !strings.HasPrefix(info.Name(), ".") {
return fmt.Errorf(
"target directory is not empty (only go.mod and files with the prefix \".\" are allowed); found existing file %q",
"target directory is not empty "+
"(only go.mod, go.sum, and files and directories with the prefix \".\" are allowed); "+
"found existing file %q",
path)
}
return nil
Expand Down

0 comments on commit 4fd2cd7

Please sign in to comment.