aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2018-07-26 12:53:31 +0200
committerMichael Muré <batolettre@gmail.com>2018-07-26 12:53:31 +0200
commit5751cd8f6befa7e5dab6e647d9747f5f20f188b3 (patch)
tree91675abff2928473eac665d2d2633258df8fa299
parenta4d403de3a8c4f3a13e1839a6681fc81a8c32199 (diff)
downloadgit-bug-5751cd8f6befa7e5dab6e647d9747f5f20f188b3.tar.gz
allow to run commands from lower than the root of a git repo
-rw-r--r--repository/git.go14
1 files 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) {