Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion cmd/work.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
22 changes: 22 additions & 0 deletions internal/config/config.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package config

import (
"context"
"fmt"
"os"
"os/exec"
"path/filepath"
"strings"
"time"
Expand All @@ -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"`
}

Expand Down Expand Up @@ -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")
Expand Down
Loading