aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Runxi Yu2026-03-08 03:01:27 +0800
committerGravatar Runxi Yu2026-03-08 03:01:40 +0800
commit5526d6d8d606b40105bc0151f037d21b1f590c08 (patch)
treea0e97ad359b4b264b5c56a3cb6eb0a6900a762fa
parentprotocol/v0v1/server/receivepack: Test 64K (diff)
signatureNo signature
receivepack: Progress writing and such
-rw-r--r--receivepack/int_test.go58
-rw-r--r--receivepack/receivepack.go9
2 files changed, 65 insertions, 2 deletions
diff --git a/receivepack/int_test.go b/receivepack/int_test.go
index 7c8825ad..d9490483 100644
--- a/receivepack/int_test.go
+++ b/receivepack/int_test.go
@@ -636,6 +636,64 @@ func TestReceivePackHookProgressUsesSideBand64K(t *testing.T) {
})
}
+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()
diff --git a/receivepack/receivepack.go b/receivepack/receivepack.go
index c3e8e4b3..d4a3f6fb 100644
--- a/receivepack/receivepack.go
+++ b/receivepack/receivepack.go
@@ -70,6 +70,11 @@ func ReceivePack(
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 @@ func ReceivePack(
),
Hook: translateHook(opts.Hook),
HookIO: service.HookIO{
- Progress: base.ProgressWriter(),
- Error: base.ErrorWriter(),
+ Progress: progressWriter,
+ Error: protoSession.ErrorWriter(),
},
})