Skip to content

Commit 6fe4cc4

Browse files
committed
Handling git not being installed (fixes #72)
1 parent 254fb25 commit 6fe4cc4

File tree

2 files changed

+2
-36
lines changed

2 files changed

+2
-36
lines changed

hdl_checker/parser_utils.py

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ def glob(pathname):
5050

5151
else:
5252
JSONDecodeError = ValueError
53+
FileNotFoundError = OSError # pylint: disable=redefined-builtin
5354

5455
def glob(pathname):
5556
"Alias for glob.iglob(pathname)"
@@ -281,21 +282,10 @@ def isGitRepo(path):
281282

282283
try:
283284
return p.exists(subp.check_output(cmd, stderr=subp.STDOUT).decode().strip())
284-
except subp.CalledProcessError:
285+
except (subp.CalledProcessError, FileNotFoundError):
285286
return False
286287

287288

288-
def _isGitRepo(path):
289-
# type: (Path) -> bool
290-
"Checks if <path> is a git repository"
291-
cmd = ["git", "-C", path.abspath, "status", "--short"]
292-
try:
293-
subp.check_call(cmd, stdout=subp.PIPE, stderr=subp.STDOUT)
294-
except subp.CalledProcessError:
295-
return False
296-
return True
297-
298-
299289
def _gitLsFiles(path_to_repo, recurse_submodules=False):
300290
# type: (Path, bool) -> Iterable[Path]
301291
"Lists files from a git repository"
@@ -386,12 +376,6 @@ def filterGitIgnoredPaths(path_to_repo, paths):
386376
"""
387377
Filters out paths that are ignored by git; paths outside the repo are kept.
388378
"""
389-
# If not on a git repo, nothing is ignored
390-
if not _isGitRepo(path_to_repo):
391-
for path in paths:
392-
yield path
393-
return
394-
395379
files = set(_gitLsFiles(path_to_repo, recurse_submodules=True))
396380
paths = set(paths)
397381

hdl_checker/tests/test_parser_utils.py

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -632,21 +632,3 @@ def test_FilterGitPaths(self):
632632
)
633633
),
634634
)
635-
636-
@timeit
637-
def test_FilterGitPathsOutOfGitRepo(self):
638-
# type: (...) -> Any
639-
"""
640-
If the base path is not a Git repo, filterGitIgnoredPaths should return
641-
all paths
642-
"""
643-
base_path = mkdtemp(prefix=__name__ + "_")
644-
self.assertFalse(isGitRepo(Path(base_path)))
645-
646-
result = list(
647-
filterGitIgnoredPaths(Path(base_path), (Path(x) for x in self.paths))
648-
)
649-
650-
_logger.info("Result: %s", result)
651-
652-
self.assertCountEqual(result, (Path(x) for x in self.paths))

0 commit comments

Comments
 (0)