Skip to content

Commit d583a76

Browse files
committed
git: Add commit validation for Reset. Fixes go-git#878
Signed-off-by: Paulo Gomes <[email protected]>
1 parent f3113d2 commit d583a76

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

options.go

+5
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,11 @@ func (o *ResetOptions) Validate(r *Repository) error {
408408
}
409409

410410
o.Commit = ref.Hash()
411+
} else {
412+
_, err := r.CommitObject(o.Commit)
413+
if err != nil {
414+
return fmt.Errorf("invalid reset option: %w", err)
415+
}
411416
}
412417

413418
return nil

options_test.go

+6
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ func (s *OptionsSuite) TestCommitOptionsParentsFromHEAD(c *C) {
2323
c.Assert(o.Parents, HasLen, 1)
2424
}
2525

26+
func (s *OptionsSuite) TestResetOptionsCommitNotFound(c *C) {
27+
o := ResetOptions{Commit: plumbing.NewHash("ab1b15c6f6487b4db16f10d8ec69bb8bf91dcabd")}
28+
err := o.Validate(s.Repository)
29+
c.Assert(err, NotNil)
30+
}
31+
2632
func (s *OptionsSuite) TestCommitOptionsCommitter(c *C) {
2733
sig := &object.Signature{}
2834

0 commit comments

Comments
 (0)