extract common into common.go

This commit is contained in:
2023-01-30 22:09:43 -08:00
parent 8b46956ed9
commit 95963a2472
3 changed files with 30 additions and 30 deletions

30
commits/common.go Normal file
View File

@@ -0,0 +1,30 @@
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
}