summaryrefslogtreecommitdiff
path: root/internal/config
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2025-06-25 22:32:56 +0300
committerPaul Buetow <paul@buetow.org>2025-06-25 22:32:56 +0300
commit7c30b68f29049704c7fafed8015169e9c8047e46 (patch)
tree2c3af6da0e87cec553d0fde02aaf04cb8c2a4e01 /internal/config
parentaf8ab19f5def6f00081b0a6d1e5b20b76683f720 (diff)
feat: add configurable work directory with default ~/git/gitsyncer-workdir
- Add work_dir field to configuration file - Set default work directory to ~/git/gitsyncer-workdir (avoiding conflict with source repo) - Support home directory expansion (~/) in work_dir config - Command-line --work-dir flag takes precedence over config file - Automatically create work directory if it doesn't exist 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
Diffstat (limited to 'internal/config')
-rw-r--r--internal/config/config.go19
1 files changed, 19 insertions, 0 deletions
diff --git a/internal/config/config.go b/internal/config/config.go
index 84f66b1..92d2c86 100644
--- a/internal/config/config.go
+++ b/internal/config/config.go
@@ -20,6 +20,7 @@ type Config struct {
Organizations []Organization `json:"organizations"`
Repositories []string `json:"repositories,omitempty"`
ExcludeBranches []string `json:"exclude_branches,omitempty"` // Regex patterns for branches to exclude
+ WorkDir string `json:"work_dir,omitempty"` // Working directory for cloning repositories
}
// Load reads and parses the configuration file
@@ -50,6 +51,24 @@ func Load(path string) (*Config, error) {
return nil, fmt.Errorf("invalid configuration: %w", err)
}
+ // Set default WorkDir if not specified
+ if cfg.WorkDir == "" {
+ home, err := os.UserHomeDir()
+ if err != nil {
+ return nil, fmt.Errorf("failed to get home directory: %w", err)
+ }
+ cfg.WorkDir = filepath.Join(home, "git", "gitsyncer-workdir")
+ }
+
+ // Expand home directory in WorkDir if needed
+ if strings.HasPrefix(cfg.WorkDir, "~/") {
+ home, err := os.UserHomeDir()
+ if err != nil {
+ return nil, fmt.Errorf("failed to get home directory: %w", err)
+ }
+ cfg.WorkDir = filepath.Join(home, cfg.WorkDir[2:])
+ }
+
return &cfg, nil
}