Skip to content

Commit 2bb8d3f

Browse files
committed
fix(doctor): resolve config path for linked worktrees
commentForkPointChange assumed .git/config at a hardcoded path, which breaks in linked worktrees where .git is a file. Now uses git rev-parse --git-path config via a new GetConfigPath method.
1 parent 13e0a5d commit 2bb8d3f

2 files changed

Lines changed: 15 additions & 5 deletions

File tree

cmd/doctor.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ package cmd
44
import (
55
"fmt"
66
"os"
7-
"path/filepath"
87
"strings"
98
"time"
109

@@ -197,6 +196,7 @@ func checkBranch(g *git.Git, cfg *config.Config, s *style.Style, branch string,
197196
if err != nil {
198197
result.issues = append(result.issues,
199198
fmt.Sprintf("Failed to compute merge-base for %s and %s: %v", parent, branch, err),
199+
)
200200
return result
201201
}
202202

@@ -238,15 +238,18 @@ func setForkPointWithComment(g *git.Git, cfg *config.Config, branch, oldSHA, new
238238
if err := cfg.SetForkPoint(branch, newSHA); err != nil {
239239
return err
240240
}
241-
commentForkPointChange(g.GetGitDir(), branch, oldSHA)
241+
commentForkPointChange(g, branch, oldSHA)
242242
return nil
243243
}
244244

245-
// commentForkPointChange inserts a comment above the stackForkPoint line in .git/config
245+
// commentForkPointChange inserts a comment above the stackForkPoint line in the git config
246246
// recording the previous value and a timestamp. This preserves provenance so old fork
247247
// points can be recovered if a fix goes wrong. Best-effort: errors are silently ignored.
248-
func commentForkPointChange(gitDir, branch, oldSHA string) {
249-
configPath := filepath.Join(gitDir, "config")
248+
func commentForkPointChange(g *git.Git, branch, oldSHA string) {
249+
configPath, err := g.GetConfigPath()
250+
if err != nil {
251+
return
252+
}
250253
data, err := os.ReadFile(configPath)
251254
if err != nil {
252255
return

internal/git/git.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,13 @@ func (g *Git) GetGitDir() string {
366366
return filepath.Join(g.repoPath, ".git")
367367
}
368368

369+
// GetConfigPath returns the path to the repo's git config file,
370+
// resolved via `git rev-parse --git-path config` so it works
371+
// correctly in linked worktrees and submodules.
372+
func (g *Git) GetConfigPath() (string, error) {
373+
return g.run("rev-parse", "--git-path", "config")
374+
}
375+
369376
// Fetch fetches from origin.
370377
func (g *Git) Fetch() error {
371378
return g.runInteractive("fetch", "origin")

0 commit comments

Comments
 (0)