(ctx *snap.Context)
| 3804 | } |
| 3805 | |
| 3806 | func runGitFetchUpstream(ctx *snap.Context) error { |
| 3807 | if err := ensureGitRepository(); err != nil { |
| 3808 | return err |
| 3809 | } |
| 3810 | |
| 3811 | remote := "upstream" |
| 3812 | remoteSpecified := false |
| 3813 | fetchAll := false |
| 3814 | prune := true |
| 3815 | |
| 3816 | for i := 0; i < ctx.NArgs(); i++ { |
| 3817 | arg := strings.TrimSpace(ctx.Arg(i)) |
| 3818 | if arg == "" { |
| 3819 | continue |
| 3820 | } |
| 3821 | |
| 3822 | switch { |
| 3823 | case arg == "--all": |
| 3824 | fetchAll = true |
| 3825 | case arg == "--no-prune": |
| 3826 | prune = false |
| 3827 | case strings.HasPrefix(arg, "--"): |
| 3828 | fmt.Fprintf(ctx.Stderr(), "Usage: %s gitFetchUpstream [--all] [--no-prune] [remote]\n", commandName) |
| 3829 | return fmt.Errorf("unknown flag %q", arg) |
| 3830 | default: |
| 3831 | remoteSpecified = true |
| 3832 | remote = arg |
| 3833 | } |
| 3834 | } |
| 3835 | |
| 3836 | if fetchAll && remoteSpecified { |
| 3837 | fmt.Fprintf(ctx.Stderr(), "Usage: %s gitFetchUpstream [--all] [--no-prune] [remote]\n", commandName) |
| 3838 | return fmt.Errorf("cannot specify a remote when using --all") |
| 3839 | } |
| 3840 | |
| 3841 | args := []string{"fetch"} |
| 3842 | var summary string |
| 3843 | if fetchAll { |
| 3844 | args = append(args, "--all") |
| 3845 | summary = "all remotes" |
| 3846 | } else { |
| 3847 | exists, _, err := gitRemoteState(remote) |
| 3848 | if err != nil { |
| 3849 | return err |
| 3850 | } |
| 3851 | if !exists { |
| 3852 | return fmt.Errorf("git remote %q not found", remote) |
| 3853 | } |
| 3854 | args = append(args, remote) |
| 3855 | summary = remote |
| 3856 | } |
| 3857 | if prune { |
| 3858 | args = append(args, "--prune") |
| 3859 | } |
| 3860 | |
| 3861 | if err := runGitCommandStreaming(ctx, args...); err != nil { |
| 3862 | return fmt.Errorf("git %s: %w", strings.Join(args, " "), err) |
| 3863 | } |
no test coverage detected