| 789 | } |
| 790 | |
| 791 | func (o *GrepOptions) validate(r *Repository) error { |
| 792 | if !o.CommitHash.IsZero() && o.ReferenceName != "" { |
| 793 | return ErrHashOrReference |
| 794 | } |
| 795 | |
| 796 | // If none of CommitHash and ReferenceName are provided, set commit hash of |
| 797 | // the repository's head. |
| 798 | if o.CommitHash.IsZero() && o.ReferenceName == "" { |
| 799 | ref, err := r.Head() |
| 800 | if err != nil { |
| 801 | return err |
| 802 | } |
| 803 | o.CommitHash = ref.Hash() |
| 804 | } |
| 805 | |
| 806 | return nil |
| 807 | } |
| 808 | |
| 809 | // PlainOpenOptions describes how opening a plain repository should be |
| 810 | // performed. |