From 5751cd8f6befa7e5dab6e647d9747f5f20f188b3 Mon Sep 17 00:00:00 2001 From: Michael Muré Date: Thu, 26 Jul 2018 12:53:31 +0200 Subject: allow to run commands from lower than the root of a git repo --- repository/git.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/repository/git.go b/repository/git.go index 17b2096f..3470958b 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) { -- cgit