Add TOML support for formulas (gt-xmyha)

- Add TOML parsing using BurntSushi/toml
- Update formula loader to try .toml first, fall back to .json
- Add `bd formula convert` command for JSON→TOML migration
- Multi-line string support for readable descriptions
- Cache git worktree/reporoot checks for performance

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Steve Yegge
2025-12-25 21:59:19 -08:00
parent 5c3a40156c
commit df5d4b384c
5 changed files with 377 additions and 14 deletions

View File

@@ -5,6 +5,7 @@ import (
"os/exec"
"path/filepath"
"strings"
"sync"
)
// GetGitDir returns the actual .git directory path for the current repository.
@@ -52,25 +53,43 @@ func GetGitHeadPath() (string, error) {
return filepath.Join(gitDir, "HEAD"), nil
}
// isWorktreeOnce ensures we only check worktree status once per process.
// This is safe because worktree status cannot change during a single command execution.
var (
isWorktreeOnce sync.Once
isWorktreeResult bool
)
// IsWorktree returns true if the current directory is in a Git worktree.
// This is determined by comparing --git-dir and --git-common-dir.
// The result is cached after the first call since worktree status doesn't
// change during a single command execution.
func IsWorktree() bool {
isWorktreeOnce.Do(func() {
isWorktreeResult = isWorktreeUncached()
})
return isWorktreeResult
}
// isWorktreeUncached performs the actual worktree check without caching.
// Called once by IsWorktree and cached for subsequent calls.
func isWorktreeUncached() bool {
gitDir := getGitDirNoError("--git-dir")
if gitDir == "" {
return false
}
commonDir := getGitDirNoError("--git-common-dir")
if commonDir == "" {
return false
}
absGit, err1 := filepath.Abs(gitDir)
absCommon, err2 := filepath.Abs(commonDir)
if err1 != nil || err2 != nil {
return false
}
return absGit != absCommon
}
@@ -103,13 +122,28 @@ func GetMainRepoRoot() (string, error) {
return mainRepoRoot, nil
}
// repoRootOnce ensures we only get repo root once per process.
var (
repoRootOnce sync.Once
repoRootResult string
)
// GetRepoRoot returns the root directory of the current git repository.
// Returns empty string if not in a git repository.
//
// This function is worktree-aware and handles Windows path normalization
// (Git on Windows may return paths like /c/Users/... or C:/Users/...).
// It also resolves symlinks to get the canonical path.
// The result is cached after the first call.
func GetRepoRoot() string {
repoRootOnce.Do(func() {
repoRootResult = getRepoRootUncached()
})
return repoRootResult
}
// getRepoRootUncached performs the actual repo root lookup without caching.
func getRepoRootUncached() string {
cmd := exec.Command("git", "rev-parse", "--show-toplevel")
output, err := cmd.Output()
if err != nil {