summaryrefslogtreecommitdiff
path: root/internal/sync/repository_setup.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2025-07-03 22:38:37 +0300
committerPaul Buetow <paul@buetow.org>2025-07-03 22:38:37 +0300
commit64095a2c8d5a3a72c55d7bd0737c5542a5aeee09 (patch)
tree0af2501374550e8fdadd4df00d245c6260c0305d /internal/sync/repository_setup.go
parent0c072d964d4d07e69d1c0af1f3b09f9adc543571 (diff)
feat: add SSH backup locations with --backup flagv0.2.0
- Add support for SSH backup locations (e.g., paul@server:git/) - Backup locations are one-way only (push only, never pull) - Automatic bare repository creation on SSH servers - Add --backup flag to opt-in to backup syncing - Backup locations are disabled by default for offline resilience - Update version to 0.2.0 This allows users to maintain private backups on home servers that may be offline without affecting regular sync operations. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
Diffstat (limited to 'internal/sync/repository_setup.go')
-rw-r--r--internal/sync/repository_setup.go39
1 files changed, 37 insertions, 2 deletions
diff --git a/internal/sync/repository_setup.go b/internal/sync/repository_setup.go
index 15d436e..3ebafbd 100644
--- a/internal/sync/repository_setup.go
+++ b/internal/sync/repository_setup.go
@@ -22,7 +22,21 @@ func (s *Syncer) setupNewRepository(repoPath string) error {
return fmt.Errorf("no organizations configured")
}
- firstOrg := &s.config.Organizations[0]
+ // Find first non-backup organization to clone from
+ var firstOrg *config.Organization
+ var firstOrgIndex int
+ for i := range s.config.Organizations {
+ if !s.config.Organizations[i].BackupLocation {
+ firstOrg = &s.config.Organizations[i]
+ firstOrgIndex = i
+ break
+ }
+ }
+
+ if firstOrg == nil {
+ return fmt.Errorf("no non-backup organizations configured to clone from")
+ }
+
if err := s.cloneRepository(firstOrg, repoPath); err != nil {
return fmt.Errorf("failed to clone repository: %w", err)
}
@@ -35,8 +49,17 @@ func (s *Syncer) setupNewRepository(repoPath string) error {
}
// Add other organizations as remotes
- for i := 1; i < len(s.config.Organizations); i++ {
+ for i := range s.config.Organizations {
+ if i == firstOrgIndex {
+ continue // Skip the first org we already cloned from
+ }
org := &s.config.Organizations[i]
+
+ // Skip backup locations if backup is not enabled
+ if org.BackupLocation && !s.backupEnabled {
+ continue
+ }
+
if err := s.addRemote(repoPath, org); err != nil {
return fmt.Errorf("failed to add remote %s: %w", s.getRemoteName(org), err)
}
@@ -52,6 +75,12 @@ func (s *Syncer) setupExistingRepository(repoPath string) error {
// Check and add any missing remotes
for i := range s.config.Organizations {
org := &s.config.Organizations[i]
+
+ // Skip backup locations if backup is not enabled
+ if org.BackupLocation && !s.backupEnabled {
+ continue
+ }
+
remoteName := s.getRemoteName(org)
// Check if remote exists
@@ -86,6 +115,12 @@ func (s *Syncer) getRemotesMap() map[string]*config.Organization {
remotes := make(map[string]*config.Organization)
for i := range s.config.Organizations {
org := &s.config.Organizations[i]
+
+ // Skip backup locations if backup is not enabled
+ if org.BackupLocation && !s.backupEnabled {
+ continue
+ }
+
remoteName := s.getRemoteName(org)
remotes[remoteName] = org
}