summaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2025-06-23 17:36:03 +0300
committerPaul Buetow <paul@buetow.org>2025-06-23 17:36:03 +0300
commit8706e6a82819c0c16a0c157283de2f14af2664c3 (patch)
treebacf3d7f61e14d0400cb541e36f5ab49de6d7a33 /cmd
parent60691a6fb610cb7f7290d6ab3a26bc74f95af611 (diff)
Add repository synchronization functionality
- Create sync package to handle git repository synchronization - Implement multi-organization sync with branch tracking - Add merge conflict detection and error handling - Support cloning, fetching, merging, and pushing across all remotes - Add --sync flag to synchronize repositories - Add --work-dir flag for working directory specification - Create test infrastructure with setup and conflict test scripts - Update config validation to support file:// URLs - Add comprehensive .gitignore entries for test artifacts The sync package automatically: - Clones repositories if not present - Fetches updates from all configured organizations - Merges changes from all remotes for each branch - Pushes synchronized changes to all organizations - Detects and reports merge conflicts for manual resolution Test with: ./test/setup_test_repos.sh && ./gitsyncer --config test/test-config.json --sync test-repo 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
Diffstat (limited to 'cmd')
-rw-r--r--cmd/gitsyncer/main.go24
1 files changed, 22 insertions, 2 deletions
diff --git a/cmd/gitsyncer/main.go b/cmd/gitsyncer/main.go
index d859747..dfee39c 100644
--- a/cmd/gitsyncer/main.go
+++ b/cmd/gitsyncer/main.go
@@ -8,6 +8,7 @@ import (
"path/filepath"
"github.com/paul/gitsyncer/internal/config"
+ "github.com/paul/gitsyncer/internal/sync"
"github.com/paul/gitsyncer/internal/version"
)
@@ -16,6 +17,8 @@ func main() {
versionFlag bool
configPath string
listOrgs bool
+ syncRepo string
+ workDir string
)
// Define command line flags
@@ -24,6 +27,8 @@ func main() {
flag.StringVar(&configPath, "config", "", "path to configuration file")
flag.StringVar(&configPath, "c", "", "path to configuration file (short)")
flag.BoolVar(&listOrgs, "list-orgs", false, "list configured organizations")
+ flag.StringVar(&syncRepo, "sync", "", "repository name to sync")
+ flag.StringVar(&workDir, "work-dir", ".gitsyncer-work", "working directory for cloning repositories")
flag.Parse()
// Handle version flag
@@ -88,8 +93,23 @@ func main() {
os.Exit(0)
}
- // TODO: Implement main gitsyncer functionality
+ // Handle sync operation
+ if syncRepo != "" {
+ syncer := sync.New(cfg, workDir)
+ if err := syncer.SyncRepository(syncRepo); err != nil {
+ log.Fatal("Sync failed:", err)
+ }
+ os.Exit(0)
+ }
+
+ // Default: show usage
fmt.Println("\ngitsyncer - Git repository synchronization tool")
fmt.Printf("Configured with %d organization(s)\n", len(cfg.Organizations))
- fmt.Println("\nUse --list-orgs to display configured organizations")
+ fmt.Println("\nUsage:")
+ fmt.Println(" gitsyncer --sync <repo-name> Sync a repository across all organizations")
+ fmt.Println(" gitsyncer --list-orgs List configured organizations")
+ fmt.Println(" gitsyncer --version Show version information")
+ fmt.Println("\nOptions:")
+ fmt.Println(" --config <path> Path to configuration file")
+ fmt.Println(" --work-dir <path> Working directory for operations (default: .gitsyncer-work)")
} \ No newline at end of file