discard git and hg errors in vcs queries

Summary:
@public
Even though internally we recover from these errors, we still show them on
standard output. Redirect errors to /dev/null instead.

Test Plan:
  infer -- buck build target

doesn't complain that git crashes on non-git repositories.
master
Jules Villard 10 years ago
parent aa7bf8e69b
commit 0062172651

@ -172,49 +172,53 @@ def infer_key(analyzer):
def vcs_branch(dir='.'): def vcs_branch(dir='.'):
cwd = os.getcwd() cwd = os.getcwd()
devnull = open(os.devnull, 'w')
try: try:
os.chdir(dir) os.chdir(dir)
branch = subprocess.check_output([ branch = subprocess.check_output(
'git', ['git',
'rev-parse', 'rev-parse',
'--abbrev-ref', '--abbrev-ref',
'HEAD', 'HEAD'],
]).decode().strip() stderr=devnull).decode().strip()
except subprocess.CalledProcessError: except subprocess.CalledProcessError:
try: try:
branch = subprocess.check_output([ branch = subprocess.check_output(
'hg', ['hg',
'id', 'id',
'-B', '-B'],
]).decode().strip() stderr=devnull).decode().strip()
except subprocess.CalledProcessError: except subprocess.CalledProcessError:
branch = 'not-versioned' branch = 'not-versioned'
finally: finally:
devnull.close()
os.chdir(cwd) os.chdir(cwd)
return branch return branch
def vcs_revision(dir='.'): def vcs_revision(dir='.'):
cwd = os.getcwd() cwd = os.getcwd()
devnull = open(os.devnull, 'w')
try: try:
os.chdir(dir) os.chdir(dir)
revision = subprocess.check_output([ revision = subprocess.check_output(
'git', ['git',
'rev-parse', 'rev-parse',
'HEAD', 'HEAD'],
]).decode().strip() stderr=devnull).decode().strip()
except subprocess.CalledProcessError: except subprocess.CalledProcessError:
try: try:
revision = subprocess.check_output([ revision = subprocess.check_output(
'hg', ['hg',
'id', 'id',
'-i', '-i'],
]).decode().strip() stderr=devnull).decode().strip()
except subprocess.CalledProcessError: except subprocess.CalledProcessError:
revision = 'not-versioned' revision = 'not-versioned'
finally: finally:
devnull.close()
os.chdir(cwd) os.chdir(cwd)
return revision return revision

Loading…
Cancel
Save