package git import ( "errors" "github.com/go-git/go-git/v5" "github.com/go-git/go-git/v5/plumbing/object" ) var () var ( MissingHeadErr = errors.New("Head not found") ) type ( GitRepository struct { path string } ) func NewGitRepository(dir string) *GitRepository { return &GitRepository{ path: dir, } } func (g *GitRepository) Path() string { return g.path } func (g *GitRepository) LastCommit() (*object.Commit, error) { repo, err := git.PlainOpen(g.path) if err != nil { return nil, err } ref, err := repo.Head() if err != nil { return nil, errors.Join(MissingHeadErr, err) } c, err := repo.CommitObject(ref.Hash()) if err != nil { return nil, err } return c, nil }