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

Method Validate

options.go:584–615  ·  view source on GitHub ↗

Validate validates the fields and sets the default values.

(r *Repository)

Source from the content-addressed store, hash-verified

582
583// Validate validates the fields and sets the default values.
584func (o *CommitOptions) Validate(r *Repository) error {
585 if o.All && o.Amend {
586 return errors.New("all and amend cannot be used together")
587 }
588
589 if o.Amend && len(o.Parents) > 0 {
590 return errors.New("parents cannot be used with amend")
591 }
592
593 if o.Author == nil {
594 if err := o.loadConfigAuthorAndCommitter(r); err != nil {
595 return err
596 }
597 }
598
599 if o.Committer == nil {
600 o.Committer = o.Author
601 }
602
603 if len(o.Parents) == 0 {
604 head, err := r.Head()
605 if err != nil && err != plumbing.ErrReferenceNotFound {
606 return err
607 }
608
609 if head != nil {
610 o.Parents = []plumbing.Hash{head.Hash()}
611 }
612 }
613
614 return nil
615}
616
617func (o *CommitOptions) loadConfigAuthorAndCommitter(r *Repository) error {
618 cfg, err := r.ConfigScoped(config.SystemScope)

Calls 3

HeadMethod · 0.80
HashMethod · 0.65