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

Method getCommitFromCheckoutOptions

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

Source from the content-addressed store, hash-verified

230}
231
232func (w *Worktree) getCommitFromCheckoutOptions(opts *CheckoutOptions) (plumbing.Hash, error) {
233 hash := opts.Hash
234 if hash.IsZero() {
235 b, err := w.r.Reference(opts.Branch, true)
236 if err != nil {
237 return plumbing.ZeroHash, err
238 }
239
240 hash = b.Hash()
241 }
242
243 o, err := w.r.Object(plumbing.AnyObject, hash)
244 if err != nil {
245 return plumbing.ZeroHash, err
246 }
247
248 switch o := o.(type) {
249 case *object.Tag:
250 if o.TargetType != plumbing.CommitObject {
251 return plumbing.ZeroHash, fmt.Errorf("%w: tag target %q", object.ErrUnsupportedObject, o.TargetType)
252 }
253
254 return o.Target, nil
255 case *object.Commit:
256 return o.Hash, nil
257 }
258
259 return plumbing.ZeroHash, fmt.Errorf("%w: %q", object.ErrUnsupportedObject, o.Type())
260}
261
262func (w *Worktree) setHEADToCommit(commit plumbing.Hash) error {
263 head := plumbing.NewHashReference(plumbing.HEAD, commit)

Callers 1

CheckoutMethod · 0.95

Calls 5

IsZeroMethod · 0.65
ReferenceMethod · 0.65
HashMethod · 0.65
TypeMethod · 0.65
ObjectMethod · 0.45

Tested by

no test coverage detected