Skip to content

Commit

Permalink
Merge pull request #1048 from pjbgf/fix-reset-validation
Browse files Browse the repository at this point in the history
git: Add commit validation for Reset
  • Loading branch information
pjbgf committed Mar 12, 2024
2 parents 6af38e0 + d583a76 commit 3f77e6f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
5 changes: 5 additions & 0 deletions options.go
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,11 @@ func (o *ResetOptions) Validate(r *Repository) error {
}

o.Commit = ref.Hash()
} else {
_, err := r.CommitObject(o.Commit)
if err != nil {
return fmt.Errorf("invalid reset option: %w", err)
}
}

return nil
Expand Down
6 changes: 6 additions & 0 deletions options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ func (s *OptionsSuite) TestCommitOptionsParentsFromHEAD(c *C) {
c.Assert(o.Parents, HasLen, 1)
}

func (s *OptionsSuite) TestResetOptionsCommitNotFound(c *C) {
o := ResetOptions{Commit: plumbing.NewHash("ab1b15c6f6487b4db16f10d8ec69bb8bf91dcabd")}
err := o.Validate(s.Repository)
c.Assert(err, NotNil)
}

func (s *OptionsSuite) TestCommitOptionsCommitter(c *C) {
sig := &object.Signature{}

Expand Down

0 comments on commit 3f77e6f

Please sign in to comment.