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)
| 35 | // pushCommand calculates the git objects to send by comparing the range |
| 36 | // of commits between the local and remote git servers. |
| 37 | func 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 | |
| 90 | func uploadsBetweenRefAndRemote(ctx *uploadContext, refnames []string) { |
| 91 | tracerx.Printf("Upload refs %v to remote %v", refnames, ctx.Remote) |
nothing calls this directly
no test coverage detected