Skip to content

Commit

Permalink
Handling git not being installed (fixes #72)
Browse files Browse the repository at this point in the history
  • Loading branch information
suoto committed Nov 29, 2019
1 parent 254fb25 commit 6fe4cc4
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 36 deletions.
20 changes: 2 additions & 18 deletions hdl_checker/parser_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ def glob(pathname):

else:
JSONDecodeError = ValueError
FileNotFoundError = OSError # pylint: disable=redefined-builtin

def glob(pathname):
"Alias for glob.iglob(pathname)"
Expand Down Expand Up @@ -281,21 +282,10 @@ def isGitRepo(path):

try:
return p.exists(subp.check_output(cmd, stderr=subp.STDOUT).decode().strip())
except subp.CalledProcessError:
except (subp.CalledProcessError, FileNotFoundError):
return False


def _isGitRepo(path):
# type: (Path) -> bool
"Checks if <path> is a git repository"
cmd = ["git", "-C", path.abspath, "status", "--short"]
try:
subp.check_call(cmd, stdout=subp.PIPE, stderr=subp.STDOUT)
except subp.CalledProcessError:
return False
return True


def _gitLsFiles(path_to_repo, recurse_submodules=False):
# type: (Path, bool) -> Iterable[Path]
"Lists files from a git repository"
Expand Down Expand Up @@ -386,12 +376,6 @@ def filterGitIgnoredPaths(path_to_repo, paths):
"""
Filters out paths that are ignored by git; paths outside the repo are kept.
"""
# If not on a git repo, nothing is ignored
if not _isGitRepo(path_to_repo):
for path in paths:
yield path
return

files = set(_gitLsFiles(path_to_repo, recurse_submodules=True))
paths = set(paths)

Expand Down
18 changes: 0 additions & 18 deletions hdl_checker/tests/test_parser_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -632,21 +632,3 @@ def test_FilterGitPaths(self):
)
),
)

@timeit
def test_FilterGitPathsOutOfGitRepo(self):
# type: (...) -> Any
"""
If the base path is not a Git repo, filterGitIgnoredPaths should return
all paths
"""
base_path = mkdtemp(prefix=__name__ + "_")
self.assertFalse(isGitRepo(Path(base_path)))

result = list(
filterGitIgnoredPaths(Path(base_path), (Path(x) for x in self.paths))
)

_logger.info("Result: %s", result)

self.assertCountEqual(result, (Path(x) for x in self.paths))

0 comments on commit 6fe4cc4

Please sign in to comment.