Hello I am writing a function to check whether a git repository url is valid or not. I want to hide the output coming from git ls-remote
. Any idea how to do that?
import subprocess
def check_git(url: str) -> bool:
try:
ret = subprocess.run(
["git", "ls-remote", "-q", "--exit-code", url, "HEAD"],
check=True,
timeout=10,
stdout=subprocess.DEVNULL,
stderr=subprocess.STDOUT,
)
if ret.returncode != 0:
return False
return True
except (subprocess.TimeoutExpired, subprocess.CalledProcessError):
return False
if not check_git("https://github.com/ghost/bar.git"):
print("nCould not find repo")
When I run this, I get a username prompt. So it seems that subprocess redirection is not working here.
python git.py
Username for 'https://github.com':
Could not find repo
New contributor
sjko5 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.