MCPcopy
hub / github.com/go-git/go-git / createBranch

Method createBranch

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

Source from the content-addressed store, hash-verified

202}
203
204func (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
232func (w *Worktree) getCommitFromCheckoutOptions(opts *CheckoutOptions) (plumbing.Hash, error) {
233 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