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
15 changes: 14 additions & 1 deletion cmd/entire/cli/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,24 @@ modifying your active branch.`,
// Check if we're in a git repository first - this is a prerequisite error,
// not a usage error, so we silence Cobra's output and use SilentError
// to prevent duplicate error output in main.go
if _, err := paths.WorktreeRoot(ctx); err != nil {
repoRoot, err := paths.WorktreeRoot(ctx)
if err != nil {
fmt.Fprintln(cmd.ErrOrStderr(), "Not a git repository. Please run 'entire enable' from within a git repository.")
return NewSilentError(errors.New("not a git repository"))
}

// Change to repo root so all paths resolve correctly.
// This ensures agent hooks (e.g., .gemini/settings.json, .claude/settings.json)
// are created at the repo root even when running from a subdirectory.
cwd, _ := os.Getwd() //nolint:forbidigo // Need CWD to detect subdirectory
if cwd != repoRoot {
if err := os.Chdir(repoRoot); err != nil { //nolint:forbidigo // Intentional chdir to repo root for correct path resolution
return fmt.Errorf("failed to change to repository root %s: %w", repoRoot, err)
}
paths.ClearWorktreeRootCache()
fmt.Fprintf(cmd.ErrOrStderr(), "Note: Running from repository root (%s)\n\n", repoRoot)
}

if err := validateSetupFlags(opts.UseLocalSettings, opts.UseProjectSettings); err != nil {
return err
}
Expand Down