Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions pkg/plugins/golang/v4/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,17 @@ func checkDir() error {
if isCapitalized && info.Name() != "PROJECT" {
return nil
}
allowedFiles := []string{
// User might use tool versions management tools to set up the environment including kubebuilder and go version
"mise.toml", // mise-en-place configuration file
".tool-versions", // asdf configuration file
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you so much for raising this one 🎉

Could we check why it’s being blocked instead?
It seems we shouldn’t block these since they’re not in disallowedExtensions.

If we start creating a full list like that, it could get huge —
so it might be better to only block the specific required cases.

What do you think? Could you please take a look? 🙂

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're welcome!

Actually, I think the variable disallowedExtensions is misnamed. It should be allowedExtensions since it is treated as a guard clause before returning the error.

I agree, init should block the files that are created by kubebuilder and leave the rest be. But, maybe there were a reason why this was implemented in the first place.

I'll dig into the repo to find out why andupdate this PR.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you a lot !!!. Sure, the reason is:

We cannot initialize or scaffold files when the target directory already contains files that the tool itself is meant to scaffold. Doing so can lead to conflicts during the command execution — and, even worse, it may overwrite existing files with different content.

To avoid these issues, the initialization process must ensure that the directory is either empty or does not contain files that overlap with those that will be generated by the scaffolding tool.

}
// Allow files used by tool versions management
for _, ext := range allowedFiles {
if info.Name() == ext {
return nil
}
}
disallowedExtensions := []string{
".go",
".yaml",
Expand Down