Skip to content

Commit

Permalink
Merge pull request #399 from tarmack/develop
Browse files Browse the repository at this point in the history
Eat stderr messages from git commands.
  • Loading branch information
yeisonvargasf committed Aug 22, 2022
2 parents 00d4633 + e010baa commit 7895e10
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions safety/util.py
Expand Up @@ -15,7 +15,6 @@
from packaging.version import parse as parse_version
from ruamel.yaml import YAML
from ruamel.yaml.error import MarkedYAMLError
import safety

from safety.constants import EXIT_CODE_FAILURE, EXIT_CODE_OK
from safety.models import Package, RequirementFile
Expand Down Expand Up @@ -213,8 +212,11 @@ def build_telemetry_data(telemetry=True):
def build_git_data():
import subprocess

def git_command(commandline):
return subprocess.run(commandline, stdout=subprocess.PIPE, stderr=subprocess.DEVNULL).stdout.decode('utf-8').strip()

try:
is_git = subprocess.run(["git", "rev-parse", "--is-inside-work-tree"], stdout=subprocess.PIPE).stdout.decode('utf-8').strip()
is_git = git_command(["git", "rev-parse", "--is-inside-work-tree"])
except Exception:
is_git = False

Expand All @@ -228,14 +230,14 @@ def build_git_data():
}

try:
result['branch'] = subprocess.run(["git", "symbolic-ref", "--short", "-q", "HEAD"], stdout=subprocess.PIPE).stdout.decode('utf-8').strip()
result['tag'] = subprocess.run(["git", "describe", "--tags", "--exact-match"], stdout=subprocess.PIPE, stderr=subprocess.DEVNULL).stdout.decode('utf-8').strip()
result['branch'] = git_command(["git", "symbolic-ref", "--short", "-q", "HEAD"])
result['tag'] = git_command(["git", "describe", "--tags", "--exact-match"])

commit = subprocess.run(["git", "describe", '--match=""', '--always', '--abbrev=40', '--dirty'], stdout=subprocess.PIPE).stdout.decode('utf-8').strip()
commit = git_command(["git", "describe", '--match=""', '--always', '--abbrev=40', '--dirty'])
result['dirty'] = commit.endswith('-dirty')
result['commit'] = commit.split("-dirty")[0]

result['origin'] = subprocess.run(["git", "remote", "get-url", "origin"], stdout=subprocess.PIPE).stdout.decode('utf-8').strip()
result['origin'] = git_command(["git", "remote", "get-url", "origin"])
except Exception:
pass

Expand Down

0 comments on commit 7895e10

Please sign in to comment.