Skip to content

Commit aa01b74

Browse files
authored
Avoid exception when git is missing (#1456)
Avoids an exception when trying to determine project root directory and git is missing and there is no .ansible-lint config either. Fixes: #1455
1 parent bbc922f commit aa01b74

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

src/ansiblelint/file_utils.py

+11-7
Original file line numberDiff line numberDiff line change
@@ -218,13 +218,17 @@ def get_yaml_files(options: Namespace) -> Dict[str, Any]:
218218

219219
def guess_project_dir() -> str:
220220
"""Return detected project dir or user home directory."""
221-
result = subprocess.run(
222-
["git", "rev-parse", "--show-toplevel"],
223-
stderr=subprocess.PIPE,
224-
stdout=subprocess.PIPE,
225-
universal_newlines=True,
226-
check=False,
227-
)
221+
try:
222+
result = subprocess.run(
223+
["git", "rev-parse", "--show-toplevel"],
224+
stderr=subprocess.PIPE,
225+
stdout=subprocess.PIPE,
226+
universal_newlines=True,
227+
check=False,
228+
)
229+
except FileNotFoundError:
230+
# if git is absent we use home directory
231+
return str(Path.home())
228232

229233
if result.returncode != 0:
230234
return str(Path.home())

0 commit comments

Comments
 (0)