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='.'):
cwd = os.getcwd()
devnull = open(os.devnull, 'w')
try:
os.chdir(dir)
branch = subprocess.check_output([
'git',
'rev-parse',
'--abbrev-ref',
'HEAD',
]).decode().strip()
branch = subprocess.check_output(
['git',
'rev-parse',
'--abbrev-ref',
'HEAD'],
stderr=devnull).decode().strip()
except subprocess.CalledProcessError:
try:
branch = subprocess.check_output([
'hg',
'id',
'-B',
]).decode().strip()
branch = subprocess.check_output(
['hg',
'id',
'-B'],
stderr=devnull).decode().strip()
except subprocess.CalledProcessError:
branch = 'not-versioned'
finally:
devnull.close()
os.chdir(cwd)
return branch
def vcs_revision(dir='.'):
cwd = os.getcwd()
devnull = open(os.devnull, 'w')
try:
os.chdir(dir)
revision = subprocess.check_output([
'git',
'rev-parse',
'HEAD',
]).decode().strip()
revision = subprocess.check_output(
['git',
'rev-parse',
'HEAD'],
stderr=devnull).decode().strip()
except subprocess.CalledProcessError:
try:
revision = subprocess.check_output([
'hg',
'id',
'-i',
]).decode().strip()
revision = subprocess.check_output(
['hg',
'id',
'-i'],
stderr=devnull).decode().strip()
except subprocess.CalledProcessError:
revision = 'not-versioned'
finally:
devnull.close()
os.chdir(cwd)
return revision

Loading…
Cancel
Save