diff --git a/repository/git.go b/repository/git.go index 17b2096f68897800091fc5996d469bcae27919d6..3470958b5335f252e6de1f850f5bf278dc5166bf 100644 --- a/repository/git.go +++ b/repository/git.go @@ -63,14 +63,16 @@ func (repo *GitRepo) runGitCommandInline(args ...string) error { // and returns the corresponding GitRepo instance if it is. func NewGitRepo(path string) (*GitRepo, error) { repo := &GitRepo{Path: path} - _, err := repo.runGitCommand("rev-parse") - if err == nil { - return repo, nil - } - if _, ok := err.(*exec.ExitError); ok { + stdout, err := repo.runGitCommand("rev-parse", "--show-toplevel") + + if err != nil { return nil, err } - return nil, err + + // Fix the path to be sure we are at the root + repo.Path = stdout + + return repo, nil } func InitGitRepo(path string) (*GitRepo, error) {