Drop unused defaultOperationMode name param, lock in planner copy · Entire

Drop unused defaultOperationMode name param, lock in planner copy

5b7223c→main·Soph·3mo ago·2 files·+52 added/-2 removed

Two small cleanups flagged during review:

Co-Authored-By: Claude Opus 4.6 (1M context) noreply@anthropic.com

Sessions

dd63b36b9c0dView transcript

Changes

2

71 unmodified lines

modeValue := operationModeFlag(defaultOperationMode(defaultMode))
if name == "plan" {
    fs.Var(&modeValue, "mode", "operation mode: sync or replicate")
}

func defaultOperationMode(name string, defaultMode gitsync.OperationMode) operationMode {
    // defaultOperationMode returns the starting value for the --mode flag.
    // Subcommands that pin a mode (sync, replicate) pass it in; plan passes ""
    // and gets sync as the default, letting --mode override it.
    ...
}

func TestBuildReplicationPlansDoesNotMutateManaged(t *testing.T) { // BuildReplicationPlans inserts prune-eligible orphan refs into a local // copy of managed. Regression guard: it must not mutate the caller's map. orphan := plumbing.NewBranchReferenceName("stale") main := plumbing.NewBranchReferenceName("main") managed := map[plumbing.ReferenceName]ManagedTarget{ main: {Kind: RefKindBranch, Label: "main"}, } desired := map[plumbing.ReferenceName]DesiredRef{ main: { Kind: RefKindBranch, Label: "main", SourceRef: main, TargetRef: main, SourceHash: plumbing.NewHash("2222222222222222222222222222222222222222"), }, } targetRefs := map[plumbing.ReferenceName]plumbing.Hash{ main: plumbing.NewHash("1111111111111111111111111111111111111111"), orphan: plumbing.NewHash("3333333333333333333333333333333333333333"), }

plans, err := BuildReplicationPlans(desired, targetRefs, managed, PlanConfig{Prune: true}) if err != nil { t.Fatalf("BuildReplicationPlans: %v", err) }

// The returned plans should include the orphan delete... var sawDelete bool for _, p := range plans { if p.TargetRef == orphan && p.Action == ActionDelete { sawDelete = true } } if !sawDelete { t.Fatalf("expected prune delete for orphan, got plans=%+v", plans) }

// ...but the caller's managed map must remain unchanged. if len(managed) != 1 { t.Fatalf("caller's managed map was mutated: %+v", managed) } if _, ok := managed[orphan]; ok { t.Fatalf("orphan leaked into caller's managed map") } }

func TestValidateMappingsRejectsDuplicateTargets(t *testing.T) { _, err := validation.ValidateMappings([]RefMapping{ {Source: "main", Target: "stable"}, }) }