aboutsummaryrefslogtreecommitdiff
path: root/pkg/service/git.go
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/service/git.go')
-rw-r--r--pkg/service/git.go29
1 files changed, 23 insertions, 6 deletions
diff --git a/pkg/service/git.go b/pkg/service/git.go
index 31a1cbb..94e2adc 100644
--- a/pkg/service/git.go
+++ b/pkg/service/git.go
@@ -1,6 +1,7 @@
package service
import (
+ "errors"
"log/slog"
"os"
"path"
@@ -31,6 +32,10 @@ type (
}
)
+var (
+ RepositoryNotFoundErr = errors.New("Repository not found")
+)
+
// TODO: make it configurable
const timeFormat = "2006.01.02 15:04:05"
@@ -84,8 +89,10 @@ func (g *GitService) ListRepositories() ([]*Repository, error) {
}
func (g *GitService) ListCommits(name, ref string) ([]*object.Commit, error) {
- // TODO: handle nil
r := g.configRepo.GetByName(name)
+ if r == nil {
+ return nil, RepositoryNotFoundErr
+ }
repo, err := git.OpenRepository(r.Path)
if err != nil {
@@ -100,8 +107,10 @@ func (g *GitService) ListCommits(name, ref string) ([]*object.Commit, error) {
}
func (g *GitService) GetTree(name, ref, path string) (*object.Tree, error) {
- // TODO: handle nil
r := g.configRepo.GetByName(name)
+ if r == nil {
+ return nil, RepositoryNotFoundErr
+ }
repo, err := git.OpenRepository(r.Path)
if err != nil {
@@ -116,8 +125,10 @@ func (g *GitService) GetTree(name, ref, path string) (*object.Tree, error) {
}
func (g *GitService) GetFileContent(name, ref, path string) (string, error) {
- // TODO: handle nil
r := g.configRepo.GetByName(name)
+ if r == nil {
+ return "", RepositoryNotFoundErr
+ }
repo, err := git.OpenRepository(r.Path)
if err != nil {
@@ -132,8 +143,10 @@ func (g *GitService) GetFileContent(name, ref, path string) (string, error) {
}
func (g *GitService) ListTags(name string) ([]*object.Tag, error) {
- // TODO: handle nil
r := g.configRepo.GetByName(name)
+ if r == nil {
+ return nil, RepositoryNotFoundErr
+ }
repo, err := git.OpenRepository(r.Path)
if err != nil {
@@ -143,8 +156,10 @@ func (g *GitService) ListTags(name string) ([]*object.Tag, error) {
}
func (g *GitService) ListBranches(name string) ([]*plumbing.Reference, error) {
- // TODO: handle nil
r := g.configRepo.GetByName(name)
+ if r == nil {
+ return nil, RepositoryNotFoundErr
+ }
repo, err := git.OpenRepository(r.Path)
if err != nil {
@@ -154,8 +169,10 @@ func (g *GitService) ListBranches(name string) ([]*plumbing.Reference, error) {
}
func (g *GitService) GetHead(name string) (*plumbing.Reference, error) {
- // TODO: handle nil
r := g.configRepo.GetByName(name)
+ if r == nil {
+ return nil, RepositoryNotFoundErr
+ }
repo, err := git.OpenRepository(r.Path)
if err != nil {