issue 178: refined git command cwd setting.

Sebastien Devaux created

For unknown reason setting .git as current directory for the called
git command fails when git-bug is called from a git hook (and it was
observed only in this case). Forcing use of current dir when the
repo path is ".git" restore the expected behavior.

Change summary

repository/git.go | 13 +++++++++++--
1 file changed, 11 insertions(+), 2 deletions(-)

Detailed changes

repository/git.go 🔗

@@ -34,10 +34,19 @@ type GitRepo struct {
 
 // Run the given git command with the given I/O reader/writers, returning an error if it fails.
 func (repo *GitRepo) runGitCommandWithIO(stdin io.Reader, stdout, stderr io.Writer, args ...string) error {
-	// fmt.Printf("[%s] Running git %s\n", repo.Path, strings.Join(args, " "))
+	repopath:=repo.Path
+	if repopath==".git" {
+		// seeduvax> trangely the git command sometimes fail for very unknown
+		// reason wihtout this replacement.
+		// observed with rev-list command when git-bug is called from git
+		// hook script, even the same command with same args runs perfectly
+		// when called directly from the same hook script. 
+		repopath=""
+	}
+	// fmt.Printf("[%s] Running git %s\n", repopath, strings.Join(args, " "))
 
 	cmd := exec.Command("git", args...)
-	cmd.Dir = repo.Path
+	cmd.Dir = repopath
 	cmd.Stdin = stdin
 	cmd.Stdout = stdout
 	cmd.Stderr = stderr