From 7c30b68f29049704c7fafed8015169e9c8047e46 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Wed, 25 Jun 2025 22:32:56 +0300 Subject: feat: add configurable work directory with default ~/git/gitsyncer-workdir MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 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 --- internal/config/config.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'internal/config') 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 } -- cgit v1.2.3