Skip to content

Commit

Permalink
git: Add commit validation for Reset. Fixes go-git#878
Browse files Browse the repository at this point in the history
Signed-off-by: Paulo Gomes <paulo.gomes@suse.com>
  • Loading branch information
pjbgf committed Mar 11, 2024
1 parent f3113d2 commit d583a76
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 @@ -408,6 +408,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 d583a76

Please sign in to comment.