Skip to content

Commit

Permalink
Merge pull request #165 from roskakori/162-fix-silent-error-on-git-fa…
Browse files Browse the repository at this point in the history
…iling

#162 Fix silent error on git failing
  • Loading branch information
roskakori authored Jul 13, 2024
2 parents 2cc2c62 + 31ae59d commit 6697e79
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
9 changes: 9 additions & 0 deletions pygount/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
from pygount.common import mapped_repr
from pygount.git_storage import GitStorage, git_remote_url_and_revision_if_any

GIT_REPO_REGEX = re.compile(r"^(https?://|git@)")

# Attempt to import chardet.
try:
import chardet.universaldetector
Expand Down Expand Up @@ -604,6 +606,13 @@ def _source_paths_and_groups_to_analyze(self, source_patterns_to_analyze) -> Lis
# TODO#113: Find a way to exclude the ugly temp folder from the source path.
result.extend(self._paths_and_group_to_analyze(git_storage.temp_folder))
else:
git_url_match = re.match(GIT_REPO_REGEX, source_pattern_to_analyze)
if git_url_match is not None:
raise pygount.Error(
'URL to git repository must end with ".git", for example '
"git@github.com:roskakori/pygount.git or "
"https://github.com/roskakori/pygount.git."
)
result.extend(self._paths_and_group_to_analyze(source_pattern_to_analyze))
except OSError as error:
assert source_pattern_to_analyze is not None
Expand Down
6 changes: 6 additions & 0 deletions tests/test_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ def test_can_skip_dot_folder(self):
scanned_names = [os.path.basename(source_path) for source_path, _ in scanner.source_paths()]
assert scanned_names == [name_to_include]

def test_fails_on_non_repo_url(self):
non_repo_urls = [["https://github.com/roskakori/pygount/"], ["git@github.com:roskakori/pygount"]]
for non_repo_url in non_repo_urls:
with analysis.SourceScanner(non_repo_url) as scanner, pytest.raises(PygountError):
next(scanner.source_paths())

def test_can_find_python_files_in_dot(self):
scanner = analysis.SourceScanner(["."], "py")
actual_paths = list(scanner.source_paths())
Expand Down

0 comments on commit 6697e79

Please sign in to comment.