From 519a0ffd9967774b77a15ca9f244236255562300 Mon Sep 17 00:00:00 2001 From: Steve Yegge Date: Sun, 7 Dec 2025 20:44:44 +1100 Subject: [PATCH] fix(autoimport): use proper YAML parsing for sync-branch config (bd-0rh) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replace fragile line-by-line parsing with yaml.Unmarshal to handle: - Indented sync-branch values - Comments containing sync-branch - Multi-line values - Values with special characters 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- cmd/bd/autoimport.go | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/cmd/bd/autoimport.go b/cmd/bd/autoimport.go index c3bda9b9..31c93fd9 100644 --- a/cmd/bd/autoimport.go +++ b/cmd/bd/autoimport.go @@ -16,6 +16,7 @@ import ( "github.com/steveyegge/beads/internal/syncbranch" "github.com/steveyegge/beads/internal/types" "github.com/steveyegge/beads/internal/utils" + "gopkg.in/yaml.v3" ) // checkAndAutoImport checks if the database is empty but git has issues. @@ -142,6 +143,12 @@ func checkGitForIssues() (int, string, string) { return 0, "", "" } +// localConfig represents the subset of config.yaml we need for auto-import. +// Using proper YAML parsing handles edge cases like comments, indentation, and special characters. +type localConfig struct { + SyncBranch string `yaml:"sync-branch"` +} + // getLocalSyncBranch reads sync-branch from the local config.yaml file. // This reads directly from the file rather than using cached config to handle // cases where CWD has changed since config initialization. @@ -158,20 +165,13 @@ func getLocalSyncBranch(beadsDir string) string { return "" } - // Simple YAML parsing for sync-branch key - // Format: "sync-branch: value" or "sync-branch: \"value\"" - for _, line := range strings.Split(string(data), "\n") { - line = strings.TrimSpace(line) - if strings.HasPrefix(line, "sync-branch:") { - value := strings.TrimPrefix(line, "sync-branch:") - value = strings.TrimSpace(value) - // Remove quotes if present - value = strings.Trim(value, "\"'") - return value - } + // Parse YAML properly to handle edge cases (comments, indentation, special chars) + var cfg localConfig + if err := yaml.Unmarshal(data, &cfg); err != nil { + return "" } - return "" + return cfg.SyncBranch } // findBeadsDir finds the .beads directory in current or parent directories