Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def get_details(location: Path) -> str:
# Maybe we are importing from a wheel or an egg:
if not location.isdir():
return ""
# Maybe we are not in a git repo:
try:
status = tsrc.git.get_status(location)
except tsrc.git.CommandError:
return ""
res = " - git: %s" % status.sha1
if status.dirty:
res += " (dirty)"
return res
def run(working_path: Path, *cmd: str, check: bool = True) -> None:
""" Run git `cmd` in given `working_path`
Raise GitCommandError if return code is non-zero and `check` is True.
"""
assert_working_path(working_path)
git_cmd = list(cmd)
git_cmd.insert(0, "git")
ui.debug(ui.lightgray, working_path, "$", ui.reset, *git_cmd)
returncode = subprocess.call(git_cmd, cwd=working_path)
if returncode != 0 and check:
raise CommandError(working_path, cmd)
git_cmd = list(cmd)
git_cmd.insert(0, "git")
options = {} # type: Dict[str, Any]
options["stdout"] = subprocess.PIPE
options["stderr"] = subprocess.STDOUT
ui.debug(ui.lightgray, working_path, "$", ui.reset, *git_cmd)
process = subprocess.Popen(git_cmd, cwd=working_path, **options)
out, _ = process.communicate()
out = out.decode("utf-8")
if out.endswith("\n"):
out = out.strip("\n")
returncode = process.returncode
ui.debug(ui.lightgray, "[%i]" % returncode, ui.reset, out)
if check and returncode != 0:
raise CommandError(working_path, cmd, output=out)
return returncode, out