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