Skip to content

Commit ece3ad9

Browse files
jpichonmergify[bot]
authored andcommitted
Check reference exists in commit.describe
Also fix test comment mismatch.
1 parent 00fed08 commit ece3ad9

File tree

3 files changed

+36
-6
lines changed

3 files changed

+36
-6
lines changed

git_wrapper/commit.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ def __init__(self, git_repo, logger):
1919
self.git_repo = git_repo
2020
self.logger = logger
2121

22+
@reference_exists('sha')
2223
def describe(self, sha):
2324
"""Return tag and commit info for a given sha
2425

integration_tests/test_commit.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
1+
import pytest
2+
3+
from git_wrapper import exceptions
14
from git_wrapper.repo import GitRepo
25

36

7+
def test_describe(repo_root):
8+
repo = GitRepo(repo_root)
9+
10+
with pytest.raises(exceptions.ReferenceNotFoundException):
11+
repo.commit.describe("doesntExist")
12+
13+
414
def test_revert(repo_root):
515
repo = GitRepo(repo_root)
616
repo.git.checkout("0.1.0")

tests/test_commit.py

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ def test_describe_tag_and_patch(mock_repo):
2222

2323
repo = GitRepo('./', mock_repo)
2424

25-
assert expected == repo.commit.describe('12345')
25+
with patch('git.repo.fun.name_to_object'):
26+
assert expected == repo.commit.describe('12345')
2627

2728

2829
def test_describe_tag_only(mock_repo):
@@ -37,7 +38,8 @@ def test_describe_tag_only(mock_repo):
3738

3839
repo = GitRepo('./', mock_repo)
3940

40-
assert expected == repo.commit.describe('12345')
41+
with patch('git.repo.fun.name_to_object'):
42+
assert expected == repo.commit.describe('12345')
4143

4244

4345
def test_describe_empty(mock_repo):
@@ -52,7 +54,8 @@ def test_describe_empty(mock_repo):
5254

5355
repo = GitRepo('./', mock_repo)
5456

55-
assert expected == repo.commit.describe('12345')
57+
with patch('git.repo.fun.name_to_object'):
58+
assert expected == repo.commit.describe('12345')
5659

5760

5861
def test_describe_sha_doesnt_exist(mock_repo):
@@ -62,10 +65,25 @@ def test_describe_sha_doesnt_exist(mock_repo):
6265
THEN a ReferenceNotFoundException is raised
6366
"""
6467
repo = GitRepo('./', mock_repo)
68+
69+
with patch('git.repo.fun.name_to_object') as mock_name_to_object:
70+
mock_name_to_object.side_effect = git.exc.BadName()
71+
with pytest.raises(exceptions.ReferenceNotFoundException):
72+
repo.commit.describe('doesntexist')
73+
74+
75+
def test_describe_sha_with_describe_failure(mock_repo):
76+
"""
77+
GIVEN GitRepo initialized with a path and repo
78+
WHEN git.describe fails
79+
THEN a DescribeException is raised
80+
"""
81+
repo = GitRepo('./', mock_repo)
6582
repo.git.describe.side_effect = git.CommandError('describe')
6683

67-
with pytest.raises(exceptions.DescribeException):
68-
repo.commit.describe('12345')
84+
with patch('git.repo.fun.name_to_object'):
85+
with pytest.raises(exceptions.DescribeException):
86+
repo.commit.describe('12345')
6987

7088

7189
def test_describe_with_lightweight_tags(mock_repo):
@@ -81,7 +99,8 @@ def test_describe_with_lightweight_tags(mock_repo):
8199

82100
repo = GitRepo('./', mock_repo)
83101

84-
assert expected == repo.commit.describe('12345')
102+
with patch('git.repo.fun.name_to_object'):
103+
assert expected == repo.commit.describe('12345')
85104

86105

87106
def test_commit(mock_repo):

0 commit comments

Comments
 (0)