diff --git a/CHANGELOG.md b/CHANGELOG.md index 13e0771..df37b5d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,6 +30,8 @@ - Reject Windows Task Scheduler intervals above 1439 minutes during planning instead of producing unsupported minute-mode commands. +- Avoid rebasing and retrying mirror pushes rejected by server policy or authentication; retry only explicit branch-divergence failures. + ## 0.18.0 - 2026-11-15 **Highlights:** Add verified private backup transfers and shared seed APIs, fix scheduler and archive-path handling, and include the Go security fix for GO-2026-6859. diff --git a/docs/packages.md b/docs/packages.md index d8846d6..eb6787c 100644 --- a/docs/packages.md +++ b/docs/packages.md @@ -47,6 +47,10 @@ pathspec magic are not expanded. Use `.` to commit the whole archive. `mirror.CleanSQLiteSidecars` preserves whitespace in the selected root path; it rejects an empty or whitespace-only root instead of selecting another tree. +Mirror branch and snapshot pushes rebase and retry only when Git reports +non-fast-forward or fetch-first divergence. Other rejections, including server +hooks and authentication failures, return without a sync attempt. + Managed sidecar trees reject overlapping source and destination roots, including mixed relative and absolute paths. Configured root symlinks remain supported; symlink directories inside a destination copy path are rejected so copying and diff --git a/mirror/mirror.go b/mirror/mirror.go index 74da0d5..78b9547 100644 --- a/mirror/mirror.go +++ b/mirror/mirror.go @@ -520,6 +520,5 @@ func redactGitURLs(text string) string { func isNonFastForward(out string) bool { lower := strings.ToLower(out) return strings.Contains(lower, "non-fast-forward") || - strings.Contains(lower, "fetch first") || - strings.Contains(lower, "failed to push some refs") + strings.Contains(lower, "fetch first") } diff --git a/mirror/mirror_test.go b/mirror/mirror_test.go index 1e71e09..5aad8cf 100644 --- a/mirror/mirror_test.go +++ b/mirror/mirror_test.go @@ -172,6 +172,74 @@ func TestPushWritesCurrentBranchToOrigin(t *testing.T) { } } +func TestNonFastForwardRequiresDivergence(t *testing.T) { + for _, tc := range []struct { + output string + want bool + }{ + {"! [rejected] main -> main (non-fast-forward)\nerror: failed to push some refs", true}, + {"! [rejected] main -> main (fetch first)\nerror: failed to push some refs", true}, + {"! [remote rejected] main -> main (pre-receive hook declined)\nerror: failed to push some refs", false}, + {"fatal: Authentication failed\nerror: failed to push some refs", false}, + {"error: failed to push some refs", false}, + } { + if got := isNonFastForward(tc.output); got != tc.want { + t.Errorf("divergence classification for %q = %v, want %v", tc.output, got, tc.want) + } + } +} + +func TestPushDoesNotRetryServerRejection(t *testing.T) { + if runtime.GOOS == "windows" { + t.Skip("POSIX server hook fixture") + } + for _, mode := range []string{"branch", "snapshot", "current snapshot"} { + t.Run(mode, func(t *testing.T) { + ctx := context.Background() + dir := t.TempDir() + remote := filepath.Join(dir, "remote.git") + if err := run(ctx, "", "git", "init", "--bare", remote); err != nil { + t.Fatal(err) + } + opts := Options{RepoPath: filepath.Join(dir, "publisher"), Remote: remote, Branch: "main"} + if err := EnsureRemote(ctx, opts); err != nil { + t.Fatal(err) + } + writeTestCommit(t, ctx, opts, "manifest.json", "base\n", "base") + if err := Push(ctx, opts); err != nil { + t.Fatal(err) + } + writeTestCommit(t, ctx, opts, "manifest.json", "next\n", "next") + if _, err := CreateImmutableTag(ctx, opts, "snapshot/rejected"); err != nil { + t.Fatal(err) + } + hook := "#!/bin/sh\necho attempt >> push-attempts\necho 'synthetic server policy rejection' >&2\nexit 1\n" + if err := os.WriteFile(filepath.Join(remote, "hooks", "pre-receive"), []byte(hook), 0o700); err != nil { + t.Fatal(err) + } + if err := run(ctx, remote, "git", "config", "core.hooksPath", filepath.Join(remote, "hooks")); err != nil { + t.Fatal(err) + } + var err error + switch mode { + case "branch": + err = Push(ctx, opts) + case "snapshot": + err = PushSnapshot(ctx, opts, "snapshot/rejected") + case "current snapshot": + err = PushCurrentSnapshot(ctx, opts, "snapshot/rejected") + } + if err == nil || !strings.Contains(err.Error(), "synthetic server policy rejection") { + t.Fatalf("server rejection not reported: %v", err) + } + attempts, err := os.ReadFile(filepath.Join(remote, "push-attempts")) + if err != nil || string(attempts) != "attempt\n" { + t.Fatalf("push attempts = %q, %v; want exactly one", attempts, err) + } + }) + } +} + func TestCommitPathsDoesNotStageUnrelatedFiles(t *testing.T) { ctx := context.Background() repo := filepath.Join(t.TempDir(), "share")