Skip to content

Commit 3f77e6f

Browse files
authored
Merge pull request go-git#1048 from pjbgf/fix-reset-validation
git: Add commit validation for Reset
2 parents 6af38e0 + d583a76 commit 3f77e6f

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
@@ -427,6 +427,11 @@ func (o *ResetOptions) Validate(r *Repository) error {
427427
}
428428

429429
o.Commit = ref.Hash()
430+
} else {
431+
_, err := r.CommitObject(o.Commit)
432+
if err != nil {
433+
return fmt.Errorf("invalid reset option: %w", err)
434+
}
430435
}
431436

432437
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)