Skip to content
Open
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
13 changes: 12 additions & 1 deletion cmd/new.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,18 @@ func createBasic(projectPath, modName string) (err error) {
return
}

return runCmd(execCommand("go", "mod", "init", modName))
if err = runCmd(execCommand("go", "mod", "init", modName)); err != nil{
return
}

//Execute go mod tidy in the project directory
installModules := execCommand("go", "mod", "tidy")
installModules.Dir = fmt.Sprintf("%s%c", projectPath, os.PathSeparator)
Comment on lines +89 to +95
Copy link

Copilot AI Feb 1, 2026

Choose a reason for hiding this comment

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

createBasic runs go mod init without setting Cmd.Dir, but sets Cmd.Dir for go mod tidy. Since the function already receives projectPath, it would be more robust/consistent to set Dir for both commands (and avoid relying on a prior os.Chdir). This also prevents go.mod being created in the wrong directory if createBasic is ever called without createProject.

Suggested change
if err := runCmd(execCommand("go", "mod", "init", modName)); err != nil {
return err
}
//Execute go mod tidy in the project directory
installModules := execCommand("go", "mod", "tidy")
installModules.Dir = fmt.Sprintf("%s%c", projectPath, os.PathSeparator)
modInit := execCommand("go", "mod", "init", modName)
modInit.Dir = projectPath
if err := runCmd(modInit); err != nil {
return err
}
// Execute go mod tidy in the project directory
installModules := execCommand("go", "mod", "tidy")
installModules.Dir = projectPath

Copilot uses AI. Check for mistakes.
if err = runCmd(installModules); err != nil{
return
}
Comment on lines +94 to +98
Copy link

Copilot AI Feb 1, 2026

Choose a reason for hiding this comment

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

go mod tidy can be affected by an enclosing go.work (workspace) file. Elsewhere the repo explicitly forces GOWORK=off when running go mod ... commands (see cmd/internal/go_mod.go:33-55). Consider applying the same environment filtering here for both go mod init and go mod tidy so project generation is isolated from the caller’s workspace.

Copilot uses AI. Check for mistakes.
Comment on lines +94 to +98
Copy link

Copilot AI Feb 1, 2026

Choose a reason for hiding this comment

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

This change adds a new externally-visible step (go mod tidy) during fiber new, but current tests don’t assert that tidy is invoked. Consider adding a unit test that captures execCommand invocations and verifies go mod tidy runs after go mod init.

Copilot uses AI. Check for mistakes.

return
}

const githubPrefix = "https://github.com/"
Expand Down