Apply ExcludeRefPrefixes to probe output · Entire
Apply ExcludeRefPrefixes to probe output
eb2d4b0→main·
Soph·2mo ago·2 files·+60 added/-0 removed
probe accepted --exclude-ref-prefix and ProbeRequest.ExcludeRefPrefixes since the flag landed, but newProbeResult serialized every ref from s.sourceRefMap verbatim — so probe --all-refs --exclude-ref-prefix refs/pull/ still listed refs/pull/* in the JSON output, breaking probe as a way to preview the same effective ref set that sync/fetch would act on.
Filter in newProbeResult so the contract holds across all command paths. Regression test goes through the CLI: seeds refs/pull/1/head and refs/notes/commits on source, runs probe --all-refs --exclude-ref-prefix refs/pull/ --json, asserts pull is absent and notes is present.
Co-Authored-By: Claude Opus 4.7 (1M context) noreply@anthropic.com
Sessions
7d2d1a10852bView transcript
Changes
2
cmd/git-sync
Mmain_test.go+57
internal/syncer
Msyncer.go+3
325 unmodified lines
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
325 unmodified lines
}
// probe --exclude-ref-prefix must filter the returned ref list — otherwise
// the CLI knob is wired but ineffective for previewing scoped state.
func TestRun_Probe_ExcludeRefPrefixFiltersReturnedRefs(t *testing.T) {
sourceRepo, sourceFS := newSourceRepo(t)
makeCommits(t, sourceRepo, sourceFS, 1)
notesRef := plumbing.ReferenceName("refs/notes/commits")
syncertest.SetRefAtBranch(t, sourceRepo, notesRef, testBranch)
pullRef := plumbing.ReferenceName("refs/pull/1/head")
syncertest.SetRefAtBranch(t, sourceRepo, pullRef, testBranch)
sourceServer := newSmartHTTPRepoServer(t, sourceRepo)
defer sourceServer.Close()
output, err := captureStdout(func() error {
return run(context.Background(), []string{
"probe",
"--all-refs",
"--exclude-ref-prefix", "refs/pull/",
"--json",
sourceServer.RepoURL(),
})
})
if err != nil {
t.Fatalf("run probe: %v\noutput=%s", err, output)
}
var result map[string]any
if err := json.Unmarshal([]byte(output), &result); err != nil {
t.Fatalf("decode probe json: %v\noutput=%s", err, output)
}
refs, ok := result["refs"].([]any)
if !ok {
t.Fatalf("expected refs array, got %#v", result["refs"])
}
var sawNotes bool
for _, raw := range refs {
entry, ok := raw.(map[string]any)
if !ok {
continue
}
name, ok := entry["name"].(string)
if !ok {
continue
}
if name == string(pullRef) {
t.Fatalf("expected %s excluded from probe output, but it appeared", pullRef)
}
if name == string(notesRef) {
sawNotes = true
}
}
if !sawNotes {
t.Fatalf("expected %s in probe output", notesRef)
}
}
// CLI smoke test for --exclude-ref-prefix under --all-refs: refs/pull/* on
// the source is trimmed, refs/notes/commits is kept.
func TestRun_Sync_ExcludeRefPrefixTrimsPullRefs(t *testing.T) {
Mcmd/git-sync/main_test.go+57