Skip to content
Open
Changes from all commits
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 @@ -86,7 +86,18 @@
return err
}

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

Check failure on line 92 in cmd/new.go

View workflow job for this annotation

GitHub Actions / lint

File is not properly formatted (gci)
//Execute go mod tidy in the project directory

Check failure on line 93 in cmd/new.go

View workflow job for this annotation

GitHub Actions / lint

commentFormatting: put a space between `//` and comment text (gocritic)
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 {

Check failure on line 96 in cmd/new.go

View workflow job for this annotation

GitHub Actions / lint

if-return: redundant if ...; err != nil check, just return error instead. (revive)
Comment on lines +94 to +96
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.

installModules.Dir is set via fmt.Sprintf("%s%c", projectPath, os.PathSeparator), which adds a trailing separator and is inconsistent with other usages (cmd.Dir = dir in cmd/internal/go_mod.go). Prefer setting Dir to projectPath (optionally cleaned with filepath.Clean) to avoid odd paths like .../project// and keep path handling consistent.

Copilot uses AI. Check for mistakes.
return err
}
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 nil
}

const (
Expand Down
Loading