From 00621726512a43aaec00601877dc5c60e662c1ad Mon Sep 17 00:00:00 2001 From: Jules Villard Date: Wed, 10 Jun 2015 23:25:25 -0100 Subject: [PATCH] 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. --- infer/bin/utils.py | 46 +++++++++++++++++++++++++--------------------- 1 file changed, 25 insertions(+), 21 deletions(-) diff --git a/infer/bin/utils.py b/infer/bin/utils.py index 11ea5cb45..82d3fcd12 100644 --- a/infer/bin/utils.py +++ b/infer/bin/utils.py @@ -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