Skip to content

Commit

Permalink
Tolerate .git directory 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.
  • Loading branch information
justinsb committed Jan 13, 2021
1 parent 26d7b42 commit 4b68253
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions pkg/plugins/golang/v3/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ limitations under the License.
package v3

import (
"errors"
"fmt"
"os"
"path/filepath"
Expand Down Expand Up @@ -187,8 +186,13 @@ func checkDir() error {
if err != nil {
return err
}
// Allow the whole .git directory tree
if info.Name() == ".git" {
return filepath.SkipDir
}
// Allow go.mod and dot-files
if info.Name() != "go.mod" && !strings.HasPrefix(info.Name(), ".") {
return errors.New("only the go.mod and files with the prefix \"(.)\" are allowed before the init")
return fmt.Errorf("target directory is not empty: only go.mod, files with the prefix \".\" and .git directories can exist before init (found %q)", path)
}
return nil
})
Expand Down

0 comments on commit 4b68253

Please sign in to comment.