Merge pull request #83 from entireio/fix/fetch-drops-mappings · Entire

Merge pull request #83 from entireio/fix/fetch-drops-mappings

df91782→main · Soph·1mo ago·2 files·+22 added/-0 removed

Carry Scope.Mappings into the fetch config

Changes

2

324 unmodified lines

325
326
327
328
329
330
331

324 unmodified lines

Source:             source,
        HTTPClient:         c.httpClient,
        Branches:           append([]string(nil), req.Scope.Branches...),
        Mappings:           validationMappings(req.Scope.Mappings),
        AllRefs:            req.Scope.AllRefs,
        ExcludeRefPrefixes: append([]string(nil), req.Scope.ExcludeRefPrefixes...),
        IncludeTags:        req.IncludeTags,

Munstable/client.go+1

99 unmodified lines

100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126

99 unmodified lines

}
}

// A mappings-scoped fetch must carry its mappings into the syncer config;
// dropping them (as buildFetchConfig used to) fetches the wrong refs.
func TestBuildFetchConfigPreservesMappings(t *testing.T) {
    req := FetchRequest{
        Source: gitsync.Endpoint{URL: "https://source.example/repo.git"},
        Scope: gitsync.RefScope{
            Mappings: []gitsync.RefMapping{{Source: "refs/heads/main", Target: "refs/heads/trunk"}},
        },
    }
    cfg, err := New(Options{}).buildFetchConfig(context.Background(), req)
    if err != nil {
        t.Fatalf("buildFetchConfig: %v", err)
    }
    if len(cfg.Mappings) != 1 {
        t.Fatalf("expected fetch config to carry 1 mapping, got %d", len(cfg.Mappings))
    }
    if cfg.Mappings[0].Source != "refs/heads/main" || cfg.Mappings[0].Target != "refs/heads/trunk" {
        t.Fatalf("unexpected mapping carried through: %+v", cfg.Mappings[0])
    }
}

func TestBuildFetchConfigCopiesHaveHashesAtCallSite(t *testing.T) {
    req := FetchRequest{
        Source:     gitsync.Endpoint{URL: "https://source.example/repo.git"},