Skip to content

Commit

Permalink
Avoid exception when git is missing (#1456)
Browse files Browse the repository at this point in the history
Avoids an exception when trying to determine project root directory
and git is missing and there is no .ansible-lint config either.

Fixes: #1455
  • Loading branch information
ssbarnea committed Mar 11, 2021
1 parent bbc922f commit aa01b74
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/ansiblelint/file_utils.py
Expand Up @@ -218,13 +218,17 @@ def get_yaml_files(options: Namespace) -> Dict[str, Any]:

def guess_project_dir() -> str:
"""Return detected project dir or user home directory."""
result = subprocess.run(
["git", "rev-parse", "--show-toplevel"],
stderr=subprocess.PIPE,
stdout=subprocess.PIPE,
universal_newlines=True,
check=False,
)
try:
result = subprocess.run(
["git", "rev-parse", "--show-toplevel"],
stderr=subprocess.PIPE,
stdout=subprocess.PIPE,
universal_newlines=True,
check=False,
)
except FileNotFoundError:
# if git is absent we use home directory
return str(Path.home())

if result.returncode != 0:
return str(Path.home())
Expand Down

0 comments on commit aa01b74

Please sign in to comment.