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

Method getCommitFromCheckoutOptions

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

Source from the content-addressed store, hash-verified

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