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

Method Validate

options.go:552–583  ·  view source on GitHub ↗

Validate validates the fields and sets the default values.

(r *Repository)

Source from the content-addressed store, hash-verified

550
551// Validate validates the fields and sets the default values.
552func (o *CommitOptions) Validate(r *Repository) error {
553 if o.All && o.Amend {
554 return errors.New("all and amend cannot be used together")
555 }
556
557 if o.Amend && len(o.Parents) > 0 {
558 return errors.New("parents cannot be used with amend")
559 }
560
561 if o.Author == nil {
562 if err := o.loadConfigAuthorAndCommitter(r); err != nil {
563 return err
564 }
565 }
566
567 if o.Committer == nil {
568 o.Committer = o.Author
569 }
570
571 if len(o.Parents) == 0 {
572 head, err := r.Head()
573 if err != nil && err != plumbing.ErrReferenceNotFound {
574 return err
575 }
576
577 if head != nil {
578 o.Parents = []plumbing.Hash{head.Hash()}
579 }
580 }
581
582 return nil
583}
584
585func (o *CommitOptions) loadConfigAuthorAndCommitter(r *Repository) error {
586 cfg, err := r.ConfigScoped(config.SystemScope)

Calls 3

HeadMethod · 0.80
HashMethod · 0.65