From 8706e6a82819c0c16a0c157283de2f14af2664c3 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Mon, 23 Jun 2025 17:36:03 +0300 Subject: Add repository synchronization functionality MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 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 --- cmd/gitsyncer/main.go | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) (limited to 'cmd') 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 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 to configuration file") + fmt.Println(" --work-dir Working directory for operations (default: .gitsyncer-work)") } \ No newline at end of file -- cgit v1.2.3