| 750 | } |
| 751 | |
| 752 | func (o *GrepOptions) validate(r *Repository) error { |
| 753 | if !o.CommitHash.IsZero() && o.ReferenceName != "" { |
| 754 | return ErrHashOrReference |
| 755 | } |
| 756 | |
| 757 | // If none of CommitHash and ReferenceName are provided, set commit hash of |
| 758 | // the repository's head. |
| 759 | if o.CommitHash.IsZero() && o.ReferenceName == "" { |
| 760 | ref, err := r.Head() |
| 761 | if err != nil { |
| 762 | return err |
| 763 | } |
| 764 | o.CommitHash = ref.Hash() |
| 765 | } |
| 766 | |
| 767 | return nil |
| 768 | } |
| 769 | |
| 770 | // PlainOpenOptions describes how opening a plain repository should be |
| 771 | // performed. |