(opts *CheckoutOptions)
| 202 | } |
| 203 | |
| 204 | func (w *Worktree) createBranch(opts *CheckoutOptions) error { |
| 205 | if err := opts.Branch.Validate(); err != nil { |
| 206 | return err |
| 207 | } |
| 208 | |
| 209 | _, err := w.r.Storer.Reference(opts.Branch) |
| 210 | if err == nil { |
| 211 | return fmt.Errorf("a branch named %q already exists", opts.Branch) |
| 212 | } |
| 213 | |
| 214 | if err != plumbing.ErrReferenceNotFound { |
| 215 | return err |
| 216 | } |
| 217 | |
| 218 | if opts.Hash.IsZero() { |
| 219 | ref, err := w.r.Head() |
| 220 | if err != nil { |
| 221 | return err |
| 222 | } |
| 223 | |
| 224 | opts.Hash = ref.Hash() |
| 225 | } |
| 226 | |
| 227 | return w.r.Storer.SetReference( |
| 228 | plumbing.NewHashReference(opts.Branch, opts.Hash), |
| 229 | ) |
| 230 | } |
| 231 | |
| 232 | func (w *Worktree) getCommitFromCheckoutOptions(opts *CheckoutOptions) (plumbing.Hash, error) { |
| 233 | hash := opts.Hash |
no test coverage detected