FetchBranches fetches the specified branches from the remote repository. If a branch doesn't exist on the remote, it will be skipped without returning an error.
(ctx context.Context, path string, branches ...string)
| 170 | // FetchBranches fetches the specified branches from the remote repository. |
| 171 | // If a branch doesn't exist on the remote, it will be skipped without returning an error. |
| 172 | func FetchBranches(ctx context.Context, path string, branches ...string) error { |
| 173 | for _, branch := range branches { |
| 174 | // fetch separately to avoid NoMatchingRefSpecError when one of the branches doesn't exist on remote |
| 175 | _, err := Run(ctx, path, "fetch", "origin", branch) |
| 176 | if err != nil { |
| 177 | if strings.Contains(err.Error(), "find remote ref") { |
| 178 | continue |
| 179 | } |
| 180 | return err |
| 181 | } |
| 182 | } |
| 183 | return nil |
| 184 | } |
| 185 | |
| 186 | // IsCommitHash reports whether s is a full hex commit hash (SHA-1 or SHA-256). |
| 187 | // Use it to validate untrusted hashes before passing them as git CLI arguments: it rules out |