From 77935d3742c56bf6486a2bb7a9cc0e931c47f25f Mon Sep 17 00:00:00 2001 From: mgreau Date: Wed, 15 Apr 2026 19:59:57 -0400 Subject: [PATCH] feat: make feature branch prefix configurable Replace hardcoded "mgreau/" branch prefix with branch_prefix config field. Falls back to git config user.name (with spaces replaced by hyphens and a 5s timeout), then no prefix. --- cmd/work.go | 8 +++++++- internal/config/config.go | 22 ++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/cmd/work.go b/cmd/work.go index 3f874cb..1415b45 100644 --- a/cmd/work.go +++ b/cmd/work.go @@ -145,7 +145,13 @@ func runWorkNew(cmd *cobra.Command, args []string) error { originPath := filepath.Join(basePath, repo) worktreeName := fmt.Sprintf("%s-%s", repo, branch) worktreePath := filepath.Join(basePath, worktreeName) - gitBranch := fmt.Sprintf("mgreau/%s", branch) + prefix := cfg.GetBranchPrefix() + var gitBranch string + if prefix != "" { + gitBranch = fmt.Sprintf("%s/%s", prefix, branch) + } else { + gitBranch = branch + } // Check if worktree already exists if _, err := os.Stat(worktreePath); err == nil { diff --git a/internal/config/config.go b/internal/config/config.go index fea3a85..f55c60f 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -1,8 +1,10 @@ package config import ( + "context" "fmt" "os" + "os/exec" "path/filepath" "strings" "time" @@ -18,6 +20,7 @@ type Config struct { PollInterval string `yaml:"poll_interval"` ClaudeBin string `yaml:"claude_bin"` Terminal string `yaml:"terminal"` // "iterm" or "ghostty" + BranchPrefix string `yaml:"branch_prefix"` Watch WatchConfig `yaml:"watch"` } @@ -153,6 +156,25 @@ func (c *Config) GetTerminal() string { return c.Terminal } +// GetBranchPrefix returns the prefix for feature branch names. +// Falls back to git config user.name (with spaces replaced by hyphens), then empty string. +func (c *Config) GetBranchPrefix() string { + if c.BranchPrefix != "" { + return c.BranchPrefix + } + // Try git config user.name; replace spaces so the prefix is branch-safe. + ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) + defer cancel() + out, err := exec.CommandContext(ctx, "git", "config", "user.name").Output() + if err == nil { + name := strings.ReplaceAll(strings.TrimSpace(string(out)), " ", "-") + if name != "" { + return name + } + } + return "" +} + // expandPaths replaces ~ with $HOME in base paths. func (c *Config) expandPaths() { home := os.Getenv("HOME")