MCPcopy Create free account
hub / github.com/entireio/git-sync / newProbeCmd

Function newProbeCmd

cmd/git-sync/probe.go:12–76  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

10)
11
12func newProbeCmd() *cobra.Command {
13 var (
14 jsonOutput bool
15 sourceAuth gitsync.EndpointAuth
16 targetAuth gitsync.EndpointAuth
17 targetURL string
18 targetFollowInfoRefsRedirect bool
19 protocolVal = newProtocolFlag()
20 req = unstable.ProbeRequest{}
21 )
22
23 cmd := &cobra.Command{
24 Use: "probe [flags] <source-url> [target-url]",
25 Short: "Inspect refs advertised by source (and optionally target)",
26 Args: cobra.MaximumNArgs(2),
27 SilenceErrors: true,
28 SilenceUsage: true,
29 RunE: func(cmd *cobra.Command, args []string) error {
30 req.Protocol = gitsync.ProtocolMode(protocolVal)
31
32 if req.Source.URL == "" && len(args) > 0 {
33 req.Source.URL = args[0]
34 }
35 if targetURL == "" && len(args) > 1 {
36 targetURL = args[1]
37 }
38 if req.Source.URL == "" {
39 return errors.New("probe requires a source repository URL")
40 }
41 if targetURL != "" {
42 req.Target = &gitsync.Endpoint{
43 URL: targetURL,
44 FollowInfoRefsRedirect: targetFollowInfoRefsRedirect,
45 }
46 }
47
48 result, err := unstable.New(unstable.Options{
49 Auth: gitsync.StaticAuthProvider{Source: sourceAuth, Target: targetAuth},
50 }).Probe(cmd.Context(), req)
51 if err != nil {
52 return fmt.Errorf("probe: %w", err)
53 }
54 printOutput(jsonOutput, result)
55 return nil
56 },
57 }
58
59 addSourceEndpoint(cmd, &req.Source)
60 cmd.Flags().StringVar(&targetURL, "target-url", "", "optional target repository URL")
61 cmd.Flags().BoolVar(&targetFollowInfoRefsRedirect, "target-follow-info-refs-redirect",
62 envBool("GITSYNC_TARGET_FOLLOW_INFO_REFS_REDIRECT"),
63 "send follow-up target RPCs to the final /info/refs redirect host")
64 addSourceAuth(cmd, &sourceAuth)
65 addTargetAuth(cmd, &targetAuth)
66
67 cmd.Flags().BoolVar(&req.IncludeTags, "tags", false, "include tag ref prefixes in probe")
68 cmd.Flags().BoolVar(&req.AllRefs, "all-refs", false, "advertise all refs/* prefixes (branches, tags, notes, pulls, custom namespaces) in the probe")
69 excludeRefPrefixFlag(cmd, &req.ExcludeRefPrefixes)

Callers 1

newRootCmdFunction · 0.85

Calls 10

NewFunction · 0.92
newProtocolFlagFunction · 0.85
printOutputFunction · 0.85
addSourceEndpointFunction · 0.85
envBoolFunction · 0.85
addSourceAuthFunction · 0.85
addTargetAuthFunction · 0.85
excludeRefPrefixFlagFunction · 0.85
addProtocolFlagFunction · 0.85
ProbeMethod · 0.45

Tested by

no test coverage detected