mirror of
https://github.com/taigrr/gico.git
synced 2026-04-02 03:09:07 -07:00
31 lines
555 B
Go
31 lines
555 B
Go
package commits
|
|
|
|
import (
|
|
"errors"
|
|
"os"
|
|
|
|
git "github.com/go-git/go-git/v5"
|
|
|
|
"github.com/taigrr/gico/types"
|
|
)
|
|
|
|
type (
|
|
Repo git.Repository
|
|
CommitSet struct {
|
|
Commits []types.Commit
|
|
Year int
|
|
}
|
|
)
|
|
|
|
func OpenRepo(directory string) (Repo, error) {
|
|
if s, err := os.Stat(directory); err != nil {
|
|
return Repo{}, err
|
|
} else {
|
|
if !s.IsDir() {
|
|
return Repo{}, errors.New("received path to non-directory for git repo")
|
|
}
|
|
}
|
|
r, err := git.PlainOpenWithOptions(directory, &(git.PlainOpenOptions{DetectDotGit: true}))
|
|
return Repo(*r), err
|
|
}
|