Clean up gitsync adapter helpers · Entire
Clean up gitsync adapter helpers
8412f23→main·
Soph·3mo ago·5 files·+114 added/-19 removed
Sessions
f2b685c45383View transcript
Changes
5
internal/gitproto
Msmarthttp.go+2
pkg/gitsync
Mclient.go+3
internalbridge
Mconfig.go+2/-2
Mmodel_test.go+82
unstable
Mclient.go+25/-17
53 unmodified lines
54
55
56
57
58
59
60
61
53 unmodified lines
}
// NewConnWithHTTPClient creates a new connection using the provided HTTP client.
// Passing nil falls back to a default client and is intended only for direct
// callers outside git-sync's normal instrumented session setup.
func NewConnWithHTTPClient(ep *transport.Endpoint, label string, auth transport.AuthMethod, httpClient *http.Client) *Conn {
if httpClient == nil {
httpClient = &http.Client{Transport: http.DefaultTransport}
}
Minternal/gitproto/smarthttp.go+2
165 unmodified lines
166 167 168 169 170 171 172 173 174
165 unmodified lines
if r.Source.URL == "" { return fmt.Errorf("source URL is required") } if r.Target != nil && r.Target.URL == "" { return fmt.Errorf("target URL is required when target endpoint is provided") } if _, err := validation.NormalizeProtocolMode(string(r.Protocol)); err != nil { return err }
Mpkg/gitsync/client.go+3
65 unmodified lines
66 67 68 69 69 70 71 72 29 unmodified lines
102 103 104 105 105 106 107 108
65 unmodified lines
Target: ToSyncerEndpoint(target, targetAuth), HTTPClient: httpClient, Branches: append([]string(nil), scope.Branches...), Mappings: validationMappings(scope.Mappings), Mappings: ToValidationMappings(scope.Mappings), IncludeTags: policy.IncludeTags, DryRun: dryRun, ShowStats: collectStats, 29 unmodified lines
return string(mode) }
func validationMappings(mappings []RefMapping) []validation.RefMapping { func ToValidationMappings(mappings []RefMapping) []validation.RefMapping { out := make([]validation.RefMapping, 0, len(mappings)) for _, mapping := range mappings { out = append(out, validation.RefMapping{
Mpkg/gitsync/internalbridge/config.go+2/-2
3 unmodified lines
4 5 6 7 8 9 10 11 12 2 unmodified lines
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
3 unmodified lines
"testing"
"github.com/go-git/go-git/v6/plumbing"
"github.com/soph/git-sync/internal/planner" "github.com/soph/git-sync/internal/syncer" }
func TestHashStringZeroHashIsEmpty(t *testing.T) { got, err := HashString(zeroHash)
if err != nil { t.Fatalf("unexpected error: %v", err) } if got != "" { t.Fatalf("HashString(zero) = %q, want empty string", got) } }
func TestFromProbeResultCopiesStableFields(t *testing.T) { got := FromProbeResult(syncer.ProbeResult{ SourceURL: "https://source.example/repo.git", TargetURL: "https://target.example/repo.git", RequestedMode: "auto", Protocol: "v2", RefPrefixes: []string{"refs/heads/"}, Capabilities: []string{"ls-refs", "fetch"}, TargetCaps: []string{"report-status"}, Refs: []syncer.RefInfo{ {Name: "refs/heads/main", Hash: plumbing.NewHash("1111111111111111111111111111111111111111")}, }, Stats: syncer.Stats{ Enabled: true, Items: map[string]*syncer.ServiceStats{ "source": {Name: "source", Requests: 2, Wants: 3}, }, }, Measurement: syncer.Measurement{Enabled: true, ElapsedMillis: 42}, })
if got.SourceURL != "https://source.example/repo.git" || got.TargetURL != "https://target.example/repo.git" { t.Fatalf("unexpected URLs: %+v", got) } if len(got.Refs) != 1 || got.Refs[0].Hash != "1111111111111111111111111111111111111111" { t.Fatalf("unexpected refs: %+v", got.Refs) } if !got.Stats.Enabled || got.Stats.Items["source"].Requests != 2 || got.Measurement.ElapsedMillis != 42 { t.Fatalf("unexpected stats/measurement: %+v %+v", got.Stats, got.Measurement) } }
func TestFromSyncResultShapesStableSummary(t *testing.T) { got := FromSyncResult(syncer.Result{ Plans: []planner.BranchPlan{ { Branch: "main", SourceRef: plumbing.ReferenceName("refs/heads/main"), TargetRef: plumbing.ReferenceName("refs/heads/main"), SourceHash: plumbing.NewHash("1111111111111111111111111111111111111111"), TargetHash: plumbing.NewHash("2222222222222222222222222222222222222222"), Kind: planner.RefKindBranch, Action: planner.ActionUpdate, Reason: "fast-forward", }, }, Pushed: 1, Skipped: 2, Blocked: 3, Deleted: 4, DryRun: true, Relay: true, RelayMode: "incremental-relay", RelayReason: "fast-forward", Batching: true, BatchCount: 5, PlannedBatchCount: 6, TempRefs: []string{"refs/gitsync/bootstrap/heads/main/1"}, BootstrapSuggested: true, Protocol: "v2", })
if len(got.Refs) != 1 || got.Refs[0].Branch != "main" { t.Fatalf("unexpected refs: %+v", got.Refs) } if got.Counts.Applied != 1 || got.Counts.Skipped != 2 || got.Counts.Blocked != 3 || got.Counts.Deleted != 4 { t.Fatalf("unexpected counts: %+v", got.Counts) } if !got.Execution.DryRun || !got.Execution.Relay || got.Execution.Mode != "incremental-relay" || got.Execution.Reason != "fast-forward" { t.Fatalf("unexpected execution summary: %+v", got.Execution) } if !got.Execution.Batch.Enabled || got.Execution.Batch.Done != 5 || got.Execution.Batch.Planned != 6 { t.Fatalf("unexpected batch summary: %+v", got.Execution.Batch) } if !got.Execution.BootstrapSuggested { t.Fatalf("expected bootstrap suggestion in execution summary") } }
func TestFromProbeResultCopiesStableFields(t *testing.T) { // Implementation of test function }
func validationMappings(mappings []gitsync.RefMapping) []validation.RefMapping { out := make([]validation.RefMapping, 0, len(mappings)) bridgeMappings := make([]internalbridge.RefMapping, 0, len(mappings)) for _, mapping := range mappings { out = append(out, validation.RefMapping{ Source: mapping.Source, Target: mapping.Target, }) bridgeMappings = append(bridgeMappings, internalbridge.RefMapping{ Source: mapping.Source, Target: mapping.Target, }) } return out }