• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

roskakori / pygount / 5468364552

pending completion
5468364552

Pull #121

github

web-flow
Merge 409bf29e9 into e2f267b89
Pull Request #121: #112 add graph for git tags

397 of 426 branches covered (93.19%)

45 of 45 new or added lines in 3 files covered. (100.0%)

1118 of 1172 relevant lines covered (95.39%)

3.82 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

97.22
/pygount/git_storage.py
1
import re
4✔
2
import shutil
4✔
3
from tempfile import mkdtemp
4✔
4
from typing import Optional, Tuple
4✔
5

6
import git
4✔
7

8
#: Regular expression to detect git url with the optional tag or branch
9
# from https://stackoverflow.com/questions/2514859/regular-expression-for-git-repository server-name
10
_GIT_URL_REGEX = re.compile(
4✔
11
    r"(?P<remote_url>((git|ssh|http(s)?)|(git@[\w.-]+))(:(//)?)([\w.@:/\-~]+)(\.git))(/)?(?P<revision>[\w./\-]+)?"
12
)
13

14

15
def git_remote_url_and_revision_if_any(git_url: str) -> Tuple[Optional[str], Optional[str]]:
4✔
16
    git_url_match = _GIT_URL_REGEX.match(git_url)
4✔
17
    return (
4✔
18
        (None, None) if git_url_match is None else (git_url_match.group("remote_url"), git_url_match.group("revision"))
19
    )
20

21

22
class GitStorage:
4✔
23
    def __init__(self, remote_url: str, revision: Optional[str] = None):
4✔
24
        assert remote_url is not None
4✔
25
        self._remote_url = remote_url
4✔
26
        self._revision = revision
4✔
27
        self._temp_folder = mkdtemp()
4✔
28
        self._repo = None
4✔
29

30
    @property
4✔
31
    def temp_folder(self) -> str:
4✔
32
        return self._temp_folder
4✔
33

34
    def extract(self):
4✔
35
        multi_options = ["--depth", "1"]
4✔
36
        if self._revision is not None:
4✔
37
            multi_options.extend(["--branch", self._revision])
4✔
38
        self._repo = git.Repo.clone_from(self._remote_url, self._temp_folder, multi_options=multi_options)
4✔
39

40
    def unshallow(self):
4✔
41
        self._repo.git.pull("--unshallow")
4✔
42

43
    def checkout(self, revision):
4✔
44
        self._repo.git.checkout(revision)
×
45

46
    def revisions(self) -> list[str]:
4✔
47
        return self._repo.tags
4✔
48

49
    def close(self):
4✔
50
        shutil.rmtree(self._temp_folder, ignore_errors=True)
4✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc