MCPcopy
hub / github.com/git-lfs/git-lfs / pushCommand

Function pushCommand

commands/command_push.go:37–88  ·  view source on GitHub ↗

pushCommand pushes local objects to a Git LFS server. It has four forms: ` ...` ` --stdin` (reads refs from stdin) ` --object-id ...` ` --object-id --stdin` (reads oids from stdin) Remote must be a remote name, not a URL. With --stdin, v

(cmd *cobra.Command, args []string)

Source from the content-addressed store, hash-verified

35// pushCommand calculates the git objects to send by comparing the range
36// of commits between the local and remote git servers.
37func pushCommand(cmd *cobra.Command, args []string) {
38 if len(args) == 0 {
39 Print(tr.Tr.Get("Specify a remote and a remote branch name (`git lfs push origin main`)"))
40 os.Exit(1)
41 }
42
43 requireGitVersion()
44
45 // Remote is first arg
46 if err := cfg.SetValidPushRemote(args[0]); err != nil {
47 Exit(tr.Tr.Get("Invalid remote name %q: %s", args[0], err))
48 }
49
50 ctx := newUploadContext(pushDryRun)
51
52 var argList []string
53 if useStdin {
54 if len(args) > 1 {
55 Print(tr.Tr.Get("Further command line arguments are ignored with --stdin"))
56 os.Exit(1)
57 }
58
59 scanner := bufio.NewScanner(os.Stdin) // line-delimited
60 for scanner.Scan() {
61 line := scanner.Text()
62 if line != "" {
63 argList = append(argList, line)
64 }
65 }
66 if err := scanner.Err(); err != nil {
67 ExitWithError(errors.Wrap(err, tr.Tr.Get("Error reading from stdin:")))
68 }
69 } else {
70 argList = args[1:]
71 }
72
73 if pushObjectIDs {
74 // We allow no object IDs with `--stdin` to make scripting
75 // easier and avoid having to special-case this in scripts.
76 if !useStdin && len(argList) < 1 {
77 Print(tr.Tr.Get("At least one object ID must be supplied with --object-id"))
78 os.Exit(1)
79 }
80 uploadsWithObjectIDs(ctx, argList)
81 } else {
82 if !useStdin && !pushAll && len(argList) < 1 {
83 Print(tr.Tr.Get("At least one ref must be supplied without --all"))
84 os.Exit(1)
85 }
86 uploadsBetweenRefAndRemote(ctx, argList)
87 }
88}
89
90func uploadsBetweenRefAndRemote(ctx *uploadContext, refnames []string) {
91 tracerx.Printf("Upload refs %v to remote %v", refnames, ctx.Remote)

Callers

nothing calls this directly

Calls 12

WrapFunction · 0.92
PrintFunction · 0.85
requireGitVersionFunction · 0.85
ExitFunction · 0.85
newUploadContextFunction · 0.85
ExitWithErrorFunction · 0.85
uploadsWithObjectIDsFunction · 0.85
SetValidPushRemoteMethod · 0.80
GetMethod · 0.65
ScanMethod · 0.65
ErrMethod · 0.65

Tested by

no test coverage detected