func findGitRepo(directory string) (string, error) {
	candidate := path.Join(directory, gitRepoDirectory)
	fileInfo, err := os.Stat(candidate)
	if !os.IsNotExist(err) && fileInfo.IsDir() {
		fileInfo, err = os.Stat(path.Join(candidate, gitRepoConfigFilename))
		if !os.IsNotExist(err) && !fileInfo.IsDir() {
			return candidate, nil
		}
	}
	if directory[len(directory)-1] == filepath.Separator {
		return "", errors.New("not found")
	}
	return findGitRepo(filepath.Dir(directory))
}
Search in the given directory a git repository directory
It goes up in the filesystem hierarchy until a repository is found, or the root is reach
A git repository directory is a '.git' folder (gitRepoDirectory constant) containing a 'config' file
(gitRepoConfigFilename constant)
package main
import (
	"errors"
	"github.com/go-ini/ini"
	"os"
	"path"
	"path/filepath"
	"regexp"
)
const gitRepoDirectory = ".git"
const gitRepoConfigFilename = "config"