Skip to content

Commit

Permalink
Allow using the daemon in a subdirectory
Browse files Browse the repository at this point in the history
  • Loading branch information
vHanda committed May 14, 2022
1 parent 68e4a8e commit cb65f32
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func daemonAdd(ctx *cli.Context) error {
// TODO: Check if the parent/ancestor is the repoPath!
}

err := isValidGitRepo(repoPath)
repoPath, err := isValidGitRepo(repoPath)
if err != nil {
return tracerr.Wrap(err)
}
Expand Down Expand Up @@ -89,22 +89,35 @@ func daemonAdd(ctx *cli.Context) error {
return nil
}

func isValidGitRepo(repoPath string) error {
func isValidGitRepo(repoPath string) (string, error) {
info, err := os.Stat(repoPath)
if os.IsNotExist(err) {
return tracerr.Errorf("%w - %s", errRepoPathInvalid, repoPath)
return "", tracerr.Errorf("%w - %s", errRepoPathInvalid, repoPath)
}

if !info.IsDir() {
return tracerr.Errorf("%w - %s", errRepoPathInvalid, repoPath)
return "", tracerr.Errorf("%w - %s", errRepoPathInvalid, repoPath)
}

_, err = git.PlainOpenWithOptions(repoPath, &git.PlainOpenOptions{DetectDotGit: true})
if err != nil {
return tracerr.Errorf("Not a valid git repo - %s\n%w", repoPath, err)
return "", tracerr.Errorf("Not a valid git repo - %s\n%w", repoPath, err)
}

return nil
for true {
_, err := os.Stat(repoPath)
if err != nil {
return "", tracerr.Errorf("%w - %s", errRepoPathInvalid, repoPath)
}

if repoPath == "." {
return "", tracerr.Errorf("%w - %s", errRepoPathInvalid, repoPath)
}

repoPath = filepath.Dir(repoPath)
}

return repoPath, nil
}

func daemonRm(ctx *cli.Context) error {
Expand Down

0 comments on commit cb65f32

Please sign in to comment.