Parse target HEAD symref into TargetFeatures · Entire
Parse target HEAD symref into TargetFeatures
29bf74c·
Soph·2mo ago·2 files·+17 added/-0 removed
Refs #45.
Co-Authored-By: Claude Opus 4.7 (1M context) noreply@anthropic.com
Sessions
9d1c1f5b25eaView transcript
Changes
2
internal/gitproto
Mtarget_features.go+6
Mtarget_features_test.go+11
1
2
3
4
5
6
7
8 unmodified lines
16
17
18
19
20
21
22
23
24
25
10 unmodified lines
36
37
38
39
40
41
package gitproto
import (
"github.com/go-git/go-git/v6/plumbing"
"github.com/go-git/go-git/v6/plumbing/protocol/packp"
"github.com/go-git/go-git/v6/plumbing/protocol/packp/capability"
)
8 unmodified lines
ReportStatus bool `json:"reportStatus"`
Sideband bool `json:"sideband"`
Sideband64k bool `json:"sideband64k"`
// HeadTarget is the branch the target's HEAD symref points at, if the
// advertisement carried a symref=HEAD:<ref> capability. Empty when HEAD
// is detached or not advertised.
HeadTarget plumbing.ReferenceName `json:"headTarget,omitempty"`
}
// TargetFeaturesFromAdvRefs derives the target-side feature summary from a
10 unmodified lines
ReportStatus: adv.Capabilities.Supports(capability.ReportStatus),
Sideband: adv.Capabilities.Supports(capability.Sideband),
Sideband64k: adv.Capabilities.Supports(capability.Sideband64k),
HeadTarget: headTargetFromAdv(adv),
}
}
Minternal/gitproto/target_features.go+6
2 unmodified lines
3
4
5
6
7
8
9
16 unmodified lines
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
2 unmodified lines
import (
"testing"
"github.com/go-git/go-git/v6/plumbing"
"github.com/go-git/go-git/v6/plumbing/protocol/packp"
"github.com/go-git/go-git/v6/plumbing/protocol/packp/capability"
"github.com/stretchr/testify/require"
16 unmodified lines
}
}
func TestTargetFeaturesFromAdvRefsHeadTarget(t *testing.T) {
adv := packp.NewAdvRefs()
require.NoError(t, adv.Capabilities.Set(capability.SymRef, "HEAD:refs/heads/main"))
got := TargetFeaturesFromAdvRefs(adv)
if got.HeadTarget != plumbing.ReferenceName("refs/heads/main") {
t.Fatalf("HeadTarget = %q, want refs/heads/main", got.HeadTarget)
}
}
func TestTargetFeaturesFromAdvRefsNil(t *testing.T) {
if got := TargetFeaturesFromAdvRefs(nil); got != (TargetFeatures{}) {
t.Fatalf("expected zero features for nil adv, got %+v", got)