@@ -10,6 +10,7 @@ import (
1010 "github.com/GitJournal/git-auto-sync/common"
1111 cli "github.com/urfave/cli/v2"
1212 "github.com/ztrue/tracerr"
13+ "golang.org/x/exp/slices"
1314 git "gopkg.in/src-d/go-git.v4"
1415)
1516
@@ -46,7 +47,6 @@ func daemonAdd(ctx *cli.Context) error {
4647 }
4748
4849 repoPath = filepath .Join (cwd , repoPath )
49- // TODO: Check if the parent/ancestor is the repoPath!
5050 }
5151
5252 repoPath , err := isValidGitRepo (repoPath )
@@ -59,15 +59,9 @@ func daemonAdd(ctx *cli.Context) error {
5959 return tracerr .Wrap (err )
6060 }
6161
62- contains := false
63- for _ , rp := range config .Repos {
64- if rp == repoPath {
65- contains = true
66- break
67- }
68- }
69-
70- if ! contains {
62+ if slices .Contains (config .Repos , repoPath ) {
63+ fmt .Println ("The Daemon is already monitoring " + repoPath )
64+ } else {
7165 config .Repos = append (config .Repos , repoPath )
7266 }
7367
@@ -105,16 +99,20 @@ func isValidGitRepo(repoPath string) (string, error) {
10599 }
106100
107101 for true {
108- _ , err := os .Stat (repoPath )
102+ info , err := os .Stat (filepath . Join ( repoPath , ".git" ) )
109103 if err != nil {
110104 return "" , tracerr .Errorf ("%w - %s" , errRepoPathInvalid , repoPath )
111105 }
112106
113- if repoPath == "." {
114- return "" , tracerr .Errorf ("%w - %s" , errRepoPathInvalid , repoPath )
107+ if os .IsNotExist (err ) {
108+ repoPath = filepath .Dir (repoPath )
109+ continue
115110 }
116111
117- repoPath = filepath .Dir (repoPath )
112+ if ! info .IsDir () {
113+ return "" , tracerr .Errorf ("%w - %s" , errRepoPathInvalid , repoPath )
114+ }
115+ break
118116 }
119117
120118 return repoPath , nil
0 commit comments