Within a python script which I would like to be able to execute from some arbitrary location within a git repositories working tree, in some arbitrary git repository, and I would like to use GitPython to extract some information about said repository.
I can get the information I need from the Repo object, but I can't figure out how to open a Repo object , but the Repo constructor requires a path to repo-root.
Is there a way to construct a Repo object with a path to somewhere in the repo, not just the repo-root location? Alternatively is there a way to query the location of repo root for a given path?
I'm looking for something like:
import git
r = git.Repo('whatever repo the cwd is in')
The following works, but I find it hopelessly clunky:
import git
import subprocess
rtpath = subprocess.check_output(["git", "rev-parse", "--show-toplevel"])
repo = git.Repo(rtpath.strip())