diff --git a/cmd/bd/compact.go b/cmd/bd/compact.go index 8856b275..402dc510 100644 --- a/cmd/bd/compact.go +++ b/cmd/bd/compact.go @@ -1019,7 +1019,9 @@ func pruneExpiredTombstones() (*TombstonePruneResult, error) { } allIssues = append(allIssues, &issue) } - file.Close() + if err := file.Close(); err != nil { + return nil, fmt.Errorf("failed to close issues file: %w", err) + } // Determine TTL ttl := types.DefaultTombstoneTTL @@ -1052,20 +1054,20 @@ func pruneExpiredTombstones() (*TombstonePruneResult, error) { encoder := json.NewEncoder(tempFile) for _, issue := range kept { if err := encoder.Encode(issue); err != nil { - tempFile.Close() - os.Remove(tempPath) + _ = tempFile.Close() + _ = os.Remove(tempPath) return nil, fmt.Errorf("failed to write issue %s: %w", issue.ID, err) } } if err := tempFile.Close(); err != nil { - os.Remove(tempPath) + _ = os.Remove(tempPath) return nil, fmt.Errorf("failed to close temp file: %w", err) } // Atomically replace if err := os.Rename(tempPath, issuesPath); err != nil { - os.Remove(tempPath) + _ = os.Remove(tempPath) return nil, fmt.Errorf("failed to replace issues.jsonl: %w", err) } diff --git a/cmd/bd/migrate_tombstones.go b/cmd/bd/migrate_tombstones.go index 5162fa3a..6ba939d6 100644 --- a/cmd/bd/migrate_tombstones.go +++ b/cmd/bd/migrate_tombstones.go @@ -128,7 +128,7 @@ Examples: existingTombstones[issue.ID] = true } } - file.Close() + _ = file.Close() } // Determine which deletions need migration diff --git a/cmd/bd/sync.go b/cmd/bd/sync.go index 92ed856a..5f0df33b 100644 --- a/cmd/bd/sync.go +++ b/cmd/bd/sync.go @@ -836,7 +836,7 @@ func gitHasChanges(ctx context.Context, filePath string) (bool, error) { // getRepoRootForWorktree returns the main repository root for running git commands // This is always the main repository root, never the worktree root -func getRepoRootForWorktree(ctx context.Context) string { +func getRepoRootForWorktree(_ context.Context) string { repoRoot, err := git.GetMainRepoRoot() if err != nil { // Fallback to current directory if GetMainRepoRoot fails diff --git a/internal/git/gitdir.go b/internal/git/gitdir.go index a627d86b..4b510d83 100644 --- a/internal/git/gitdir.go +++ b/internal/git/gitdir.go @@ -2,6 +2,7 @@ package git import ( "fmt" + "os" "os/exec" "path/filepath" "strings" @@ -106,7 +107,7 @@ func GetMainRepoRoot() (string, error) { commonDir := getGitDirNoError("--git-common-dir") if commonDir != "" { // Validate that commonDir exists - if _, err := exec.Command("test", "-d", commonDir).Output(); err == nil { + if info, err := os.Stat(commonDir); err == nil && info.IsDir() { return filepath.Dir(commonDir), nil } }