ref: 5526d6d8d606b40105bc0151f037d21b1f590c08
parent: af5073e78472e5e25ce893aa8c33356996ff8d09
author: Runxi Yu <me@runxiyu.org>
date: Sat Mar 7 22:01:27 EST 2026
receivepack: Progress writing and such
--- a/receivepack/int_test.go
+++ b/receivepack/int_test.go
@@ -636,6 +636,64 @@
})
}
+func TestReceivePackQuietSuppressesProgressStream(t *testing.T) {+ t.Parallel()
+
+ //nolint:thelper
+ testgit.ForEachAlgorithm(t, func(t *testing.T, algo objectid.Algorithm) {+ t.Parallel()
+
+ testRepo := testgit.NewRepo(t, testgit.RepoOptions{ObjectFormat: algo})+ _, _, commitID := testRepo.MakeCommit(t, "base")
+ testRepo.UpdateRef(t, "refs/heads/main", commitID)
+
+ repo := testRepo.OpenRepository(t)
+
+ var (
+ input strings.Builder
+ output bufferWriteFlusher
+ )
+
+ input.WriteString(pktlineData(
+ commitID.String() + " " + objectid.Zero(algo).String() + " refs/heads/main\x00report-status side-band-64k quiet atomic delete-refs object-format=" + algo.String() + "\n",
+ ))
+ input.WriteString("0000")+
+ err := receivepack.ReceivePack(context.Background(), &output, strings.NewReader(input.String()), receivepack.Options{+ Algorithm: algo,
+ Refs: repo.Refs(),
+ ExistingObjects: repo.Objects(),
+ Hook: func(ctx context.Context, req receivepack.HookRequest) ([]receivepack.UpdateDecision, error) {+ _, err := io.WriteString(req.IO.Progress, "hook says hello\n")
+ if err != nil {+ return nil, err
+ }
+
+ return []receivepack.UpdateDecision{{Accept: true}}, nil+ },
+ })
+ if err != nil {+ t.Fatalf("ReceivePack: %v", err)+ }
+
+ _, sidebandWire, ok := strings.Cut(output.String(), "0000")
+ if !ok {+ t.Fatalf("output missing advertisement flush: %q", output.String())+ }
+
+ dec := sideband64k.NewDecoder(strings.NewReader(sidebandWire), sideband64k.ReadOptions{})+
+ frame, err := dec.ReadFrame()
+ if err != nil {+ t.Fatalf("ReadFrame(first): %v", err)+ }
+
+ if frame.Type != sideband64k.FrameData {+ t.Fatalf("first frame.Type = %v, want FrameData", frame.Type)+ }
+ })
+}
+
func TestReceivePackPredefinedRejectForcePushHookRejectsNonFastForward(t *testing.T) {t.Parallel()
--- a/receivepack/receivepack.go
+++ b/receivepack/receivepack.go
@@ -70,6 +70,11 @@
return err
}
+ progressWriter := protoSession.ProgressWriter()
+ if req.Capabilities.Quiet {+ progressWriter = io.Discard
+ }
+
serviceReq := &service.Request{Commands: translateCommands(req.Commands),
PushOptions: append([]string(nil), req.PushOptions...),
@@ -89,8 +94,8 @@
),
Hook: translateHook(opts.Hook),
HookIO: service.HookIO{- Progress: base.ProgressWriter(),
- Error: base.ErrorWriter(),
+ Progress: progressWriter,
+ Error: protoSession.ErrorWriter(),
},
})
--
⑨