Skip to content

Commit

Permalink
Add: Allow to get the git version string
Browse files Browse the repository at this point in the history
  • Loading branch information
bjoernricks committed Jul 19, 2023
1 parent d4d5c12 commit 1e0c32e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
8 changes: 8 additions & 0 deletions pontos/git/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,14 @@ def cwd(self, cwd: Path) -> None:
"""
self._cwd = cwd.absolute()

@property
def version(self) -> str:
"""
Get the version string of the installed git
"""
# git --version returns "git version 2.3.4"
return self.exec("--version").strip().rsplit(" ", 1)[1]

def exec(self, *args: str) -> str:
return exec_git(*args, cwd=self._cwd)

Expand Down
13 changes: 12 additions & 1 deletion tests/git/test_git.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import unittest
from pathlib import Path
from unittest.mock import patch
from unittest.mock import MagicMock, patch

from pontos.git import Git
from pontos.git.git import (
Expand Down Expand Up @@ -624,6 +624,17 @@ def test_status_with_files(self, exec_git_mock):
cwd=None,
)

@patch("pontos.git.git.exec_git")
def test_version(self, exec_git_mock: MagicMock):
exec_git_mock.return_value = "git version 1.2.3"
git = Git()
self.assertEqual(git.version, "1.2.3")

def test_version_runs(self):
"""Getting the git version should not raise an error"""
git = Git()
git.version


class GitExtendedTestCase(unittest.TestCase):
def test_semantic_list_tags(self):
Expand Down

0 comments on commit 1e0c32e

Please sign in to comment.