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

Function newSyncLikeCmd

cmd/git-sync/syncplan.go:25–149  ·  view source on GitHub ↗
(name, short string, dryRun bool, defaultMode gitsync.OperationMode)

Source from the content-addressed store, hash-verified

23}
24
25func newSyncLikeCmd(name, short string, dryRun bool, defaultMode gitsync.OperationMode) *cobra.Command {
26 var (
27 mappings []string
28 jsonOutput bool
29 sourceAuth gitsync.EndpointAuth
30 targetAuth gitsync.EndpointAuth
31 branches string
32 modeValue = operationModeFlag(defaultOperationMode(defaultMode))
33 protocolVal = newProtocolFlag()
34 legacyForce bool
35 req = unstable.SyncRequest{DryRun: dryRun}
36 )
37
38 cmd := &cobra.Command{
39 Use: name + " [flags] <source-url> <target-url>",
40 Short: short,
41 Args: cobra.MaximumNArgs(2),
42 SilenceErrors: true,
43 SilenceUsage: true,
44 RunE: func(cmd *cobra.Command, args []string) error {
45 if legacyForce {
46 return errors.New("--force has been removed; use --force-with-lease (previous semantics) or --force-blind (real overwrite)")
47 }
48 req.Policy.Mode = gitsync.OperationMode(modeValue)
49 req.Policy.Protocol = gitsync.ProtocolMode(protocolVal)
50
51 if req.Source.URL == "" && len(args) > 0 {
52 req.Source.URL = args[0]
53 }
54 if req.Target.URL == "" && len(args) > 1 {
55 req.Target.URL = args[1]
56 }
57
58 if branches != "" {
59 req.Scope.Branches = splitCSV(branches)
60 }
61 for _, raw := range mappings {
62 mapping, err := validation.ParseMapping(raw)
63 if err != nil {
64 return fmt.Errorf("parse mapping %q: %w", raw, err)
65 }
66 req.Scope.Mappings = append(req.Scope.Mappings, gitsync.RefMapping{
67 Source: mapping.Source,
68 Target: mapping.Target,
69 })
70 }
71
72 if req.Source.URL == "" || req.Target.URL == "" {
73 return fmt.Errorf("%s requires source and target repository URLs", name)
74 }
75
76 client := unstable.New(unstable.Options{
77 Auth: gitsync.StaticAuthProvider{Source: sourceAuth, Target: targetAuth},
78 })
79
80 var (
81 result unstable.Result
82 err error

Callers 3

newSyncCmdFunction · 0.85
newReplicateCmdFunction · 0.85
newPlanCmdFunction · 0.85

Calls 15

ParseMappingFunction · 0.92
NewFunction · 0.92
operationModeFlagTypeAlias · 0.85
defaultOperationModeFunction · 0.85
newProtocolFlagFunction · 0.85
printOutputFunction · 0.85
addSourceEndpointFunction · 0.85
addTargetEndpointFunction · 0.85
addSourceAuthFunction · 0.85
addTargetAuthFunction · 0.85
allRefsFlagFunction · 0.85
excludeRefPrefixFlagFunction · 0.85

Tested by

no test coverage detected