-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathrepository_store.go
More file actions
49 lines (36 loc) · 875 Bytes
/
repository_store.go
File metadata and controls
49 lines (36 loc) · 875 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package main
import (
"errors"
"os"
"strings"
)
type RepositoryStore interface {
GetRepository(string) (Repository, error)
}
type GitRepositoryStore struct {
path string
}
var _ RepositoryStore = &GitRepositoryStore{}
func (s *GitRepositoryStore) GetRepository(path string) (Repository, error) {
path = strings.Trim(path, "/")
fullPath := s.fullRepoPath(path)
if !s.isGitRepo(fullPath) {
path = path + "/.git"
fullPath = s.fullRepoPath(path)
if !s.isGitRepo(fullPath) {
return nil, errors.New(path + " is not a path to a git repository")
}
}
return &GitRepository{fullPath}, nil
}
func (s *GitRepositoryStore) fullRepoPath(path string) string {
return s.path + "/" + path
}
func (s *GitRepositoryStore) isGitRepo(path string) bool {
refsPath := path + "/refs"
_, err := os.Stat(refsPath)
if err == nil {
return true
}
return false
}