MCPcopy
hub / github.com/GitGuardian/ggshield / get_git_root

Function get_git_root

ggshield/utils/git_shell.py:162–182  ·  view source on GitHub ↗

Fetches the root of the git repo. This corresponds to the root directory in the case of a working tree, or the `.git/` directory in the case of a quarantine during pre-receive. :param wd: working directory, defaults to None :return: absolute path to the git root, as a string.

(wd: Optional[Union[str, Path]] = None)

Source from the content-addressed store, hash-verified

160
161
162def get_git_root(wd: Optional[Union[str, Path]] = None) -> Path:
163 """
164 Fetches the root of the git repo.
165 This corresponds to the root directory in the case of a working tree,
166 or the `.git/` directory in the case of a quarantine during pre-receive.
167
168 :param wd: working directory, defaults to None
169 :return: absolute path to the git root, as a string.
170 """
171 if wd is None:
172 wd = Path.cwd()
173 else:
174 wd = Path(wd)
175 check_git_dir(wd)
176 top_level = _git_rev_parse(option="--show-toplevel", wd=wd)
177 if top_level is not None:
178 return Path(top_level)
179 root = _git_rev_parse(option="--git-dir", wd=wd)
180 if root is None:
181 raise NotAGitDirectory()
182 return Path(root).resolve()
183
184
185def check_git_dir(wd: Optional[Union[str, Path]] = None) -> None:

Callers 2

_find_dot_envFunction · 0.90
get_project_root_dirFunction · 0.90

Calls 3

check_git_dirFunction · 0.85
_git_rev_parseFunction · 0.85
NotAGitDirectoryClass · 0.85

Tested by

no test coverage detected