Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## 0.47.2 - Unreleased

- Backup: allow a locally initialized backup to acquire its first configured remote without replacing an existing origin. (#1287) — thanks @NasAndNora.

- Gmail: give every outgoing attachment a unique, stable `X-Attachment-Id`, including duplicate files, while preserving inline Content-ID references. (#1299, #1300) — thanks @zupolgec.

- Auth: retain the command runtime and OAuth client dependencies during automatic reauthorization, preserving cancellation and the stored service/scope grant. (#1277, #1278) — thanks @TheAngryPit.
Expand Down
4 changes: 3 additions & 1 deletion docs/backup.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ gog backup init --remote https://github.com/your-account/your-private-backup.git

`init` and `push` commit locally and explain that no upload happened when no
remote is configured. Explicitly saved remotes and existing Git `origin` URLs
continue to work without rewriting them. Checkpoint pushes follow the same rule.
continue to work without rewriting them. Configuring a remote after local
initialization adds `origin` only when it is missing. Checkpoint pushes follow
the same rule.

Back up all supported services:

Expand Down
36 changes: 36 additions & 0 deletions internal/backup/backup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1071,3 +1071,39 @@ func TestBackupExistingOriginPreservedAndPushed(t *testing.T) {
t.Fatalf("snapshot not pushed: %q %v", remoteHead, err)
}
}

func TestInitAddsConfiguredRemoteToLocalRepository(t *testing.T) {
ctx, repo, config, _ := initTestBackup(t)
remote := filepath.Join(t.TempDir(), "remote.git")
if err := git(ctx, "", "init", "--bare", remote); err != nil {
t.Fatal(err)
}
if _, _, initErr := Init(ctx, testOptions(t, Options{ConfigPath: config, Remote: remote, Push: true})); initErr != nil {
t.Fatal(initErr)
}
origin, err := gitOutput(ctx, repo, "remote", "get-url", "origin")
if err != nil || strings.TrimSpace(origin) != remote {
t.Fatalf("configured origin missing: %q %v", origin, err)
}
if _, pushErr := PushSnapshot(ctx, Snapshot{Services: []string{"gmail"}}, testOptions(t, Options{ConfigPath: config, Push: true})); pushErr != nil {
t.Fatal(pushErr)
}
localHead, err := gitOutput(ctx, repo, "rev-parse", "HEAD")
if err != nil {
t.Fatal(err)
}
if _, hasErr := gitOutput(ctx, remote, "cat-file", "-e", strings.TrimSpace(localHead)); hasErr != nil {
t.Fatalf("configured backup was not pushed: %v", hasErr)
}
otherRemote := filepath.Join(t.TempDir(), "other.git")
if remoteErr := git(ctx, "", "init", "--bare", otherRemote); remoteErr != nil {
t.Fatal(remoteErr)
}
if _, _, initErr := Init(ctx, testOptions(t, Options{ConfigPath: config, Remote: otherRemote})); initErr != nil {
t.Fatal(initErr)
}
origin, err = gitOutput(ctx, repo, "remote", "get-url", "origin")
if err != nil || strings.TrimSpace(origin) != remote {
t.Fatalf("existing origin was rewritten: %q %v", origin, err)
}
}
5 changes: 5 additions & 0 deletions internal/backup/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ func ensureRepo(ctx context.Context, cfg Config) error {
return fmt.Errorf("backup repo path is required")
}
if _, err := os.Stat(filepath.Join(cfg.Repo, ".git")); err == nil {
if strings.TrimSpace(cfg.Remote) != "" && !HasRemote(ctx, cfg.Repo) {
if addErr := git(ctx, cfg.Repo, "remote", "add", "origin", cfg.Remote); addErr != nil {
return addErr
}
}
return pullRepo(ctx, cfg.Repo)
}
if strings.TrimSpace(cfg.Remote) != "" {
Expand Down
Loading