MCPcopy Create free account
hub / github.com/go-git/go-git / createBranch

Method createBranch

worktree.go:201–227  ·  view source on GitHub ↗
(opts *CheckoutOptions)

Source from the content-addressed store, hash-verified

199}
200
201func (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
229func (w *Worktree) getCommitFromCheckoutOptions(opts *CheckoutOptions) (plumbing.Hash, error) {
230 hash := opts.Hash

Callers 1

CheckoutMethod · 0.95

Calls 7

NewHashReferenceFunction · 0.92
HeadMethod · 0.80
ReferenceMethod · 0.65
IsZeroMethod · 0.65
HashMethod · 0.65
SetReferenceMethod · 0.65
ValidateMethod · 0.45

Tested by

no test coverage detected