8ad99d8219376d1d6b6915096e1404a282776d8e

Author
Ayman Bagabas <ayman.bagabas@gmail.com>
Committer
Ayman Bagabas <ayman.bagabas@gmail.com>
Date

Message

refactor(git): use repo path instead of name

Diff

 1diff --git a/internal/git/git.go b/internal/git/git.go
 2index 7cbd469849e185d641c700fae01a0a74a72c8e2e..010e22f16014112e617eefa867f64b7d9fa9c002 100644
 3--- a/internal/git/git.go
 4+++ b/internal/git/git.go
 5@@ -23,7 +23,7 @@ var ErrMissingRepo = errors.New("missing repo")
 6 
 7 // Repo represents a Git repository.
 8 type Repo struct {
 9-	name       string
10+	path       string
11 	repository *git.Repository
12 	Readme     string
13 	refCommits map[plumbing.Hash]gitypes.Commits
14@@ -36,7 +36,7 @@ type Repo struct {
15 
16 // GetName returns the name of the repository.
17 func (r *Repo) Name() string {
18-	return r.name
19+	return filepath.Base(r.path)
20 }
21 
22 // GetHEAD returns the reference for a repository.
23@@ -238,7 +238,7 @@ func (rs *RepoSource) GetRepo(name string) (*Repo, error) {
24 	rs.mtx.Lock()
25 	defer rs.mtx.Unlock()
26 	for _, r := range rs.repos {
27-		if r.name == name {
28+		if filepath.Base(r.path) == name {
29 			return r, nil
30 		}
31 	}
32@@ -265,7 +265,7 @@ func (rs *RepoSource) InitRepo(name string, bare bool) (*Repo, error) {
33 		rg = ar
34 	}
35 	r := &Repo{
36-		name:       name,
37+		path:       rp,
38 		repository: rg,
39 	}
40 	rs.repos = append(rs.repos, r)
41@@ -282,12 +282,12 @@ func (rs *RepoSource) LoadRepos() error {
42 	}
43 	rs.repos = make([]*Repo, 0)
44 	for _, de := range rd {
45-		rn := de.Name()
46-		rg, err := git.PlainOpen(filepath.Join(rs.Path, rn))
47+		rp := filepath.Join(rs.Path, de.Name())
48+		rg, err := git.PlainOpen(rp)
49 		if err != nil {
50 			return err
51 		}
52-		r, err := rs.loadRepo(rn, rg)
53+		r, err := rs.loadRepo(rp, rg)
54 		if err != nil {
55 			return err
56 		}
57@@ -296,9 +296,9 @@ func (rs *RepoSource) LoadRepos() error {
58 	return nil
59 }
60 
61-func (rs *RepoSource) loadRepo(name string, rg *git.Repository) (*Repo, error) {
62+func (rs *RepoSource) loadRepo(path string, rg *git.Repository) (*Repo, error) {
63 	r := &Repo{
64-		name:       name,
65+		path:       path,
66 		repository: rg,
67 		patch:      make(map[plumbing.Hash]*object.Patch),
68 	}
69@@ -362,3 +362,4 @@ func (r *Repo) LatestFile(path string) (string, error) {
70 func (r *Repo) LatestTree(path string) (*object.Tree, error) {
71 	return r.Tree(r.head, path)
72 }
73+