mirror of
https://github.com/taigrr/gico.git
synced 2026-04-02 03:09:07 -07:00
extract common into common.go
This commit is contained in:
30
commits/common.go
Normal file
30
commits/common.go
Normal 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
|
||||
}
|
||||
Reference in New Issue
Block a user