Repository: roskakori/pygount

Issue:
Fix silent error on git failing
Steps to reproduce:

1. Run:
   ```sh
   pygount https://github.com/roskakori/pygount/
   ```
2. No output shows.

Expected behavior:

If the specified path starts with `http[s]://` or `git@` but the regex for a full repository path does not match, the following error message shows:

> URL to git repository must end with ".git", for example git@github.com:roskakori/pygount.git or https://github.com/roskakori/pygount.git.

Discussion:

Patch:
diff --git a/pygount/analysis.py b/pygount/analysis.py
index 5246e4f..72b9cf3 100644
--- a/pygount/analysis.py
+++ b/pygount/analysis.py
@@ -27,6 +27,8 @@ import pygount.xmldialect
 from pygount.common import deprecated, 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
@@ -624,6 +626,13 @@ class SourceScanner:
                     # 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


Test patch:
diff --git a/tests/test_analysis.py b/tests/test_analysis.py
index 5fe4af6..9a09a43 100644
--- a/tests/test_analysis.py
+++ b/tests/test_analysis.py
@@ -64,6 +64,12 @@ class SourceScannerTest(TempFolderTest):
         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())