Compare commits
No commits in common. "d196155bf7b5c9883a7cb8878f084c762759dc0b" and "7083ca48c0d54e7641a05ecfd1c7d03074e3c45a" have entirely different histories.
d196155bf7
...
7083ca48c0
|
@ -282,9 +282,15 @@ def has_commits_on_branch(cwd: Path, base_branch: str, current_branch: str) -> b
|
||||||
True if there are commits on the current branch not in the base branch, False otherwise.
|
True if there are commits on the current branch not in the base branch, False otherwise.
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
commit_messages = get_commit_messages(cwd, base_branch, current_branch)
|
result = subprocess.run(
|
||||||
return bool(list(commit_messages))
|
['git', 'log', f'{base_branch}..{current_branch}', '--oneline'],
|
||||||
except Exception:
|
check=True,
|
||||||
|
cwd=cwd,
|
||||||
|
capture_output=True,
|
||||||
|
text=True,
|
||||||
|
)
|
||||||
|
return bool(result.stdout.strip())
|
||||||
|
except subprocess.CalledProcessError:
|
||||||
logger.exception('Failed to check commits on branch %s', current_branch)
|
logger.exception('Failed to check commits on branch %s', current_branch)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
|
@ -1,54 +0,0 @@
|
||||||
from pathlib import Path
|
|
||||||
from unittest.mock import patch
|
|
||||||
|
|
||||||
from aider_gitea import has_commits_on_branch
|
|
||||||
|
|
||||||
|
|
||||||
class TestHasCommitsOnBranch:
|
|
||||||
def setup_method(self):
|
|
||||||
self.cwd = Path('/tmp/test-repo')
|
|
||||||
self.base_branch = 'main'
|
|
||||||
self.current_branch = 'feature-branch'
|
|
||||||
|
|
||||||
@patch('aider_gitea.get_commit_messages')
|
|
||||||
def test_has_commits_true(self, mock_get_commit_messages):
|
|
||||||
# Setup mock to return some commit messages
|
|
||||||
mock_get_commit_messages.return_value = ['Commit 1', 'Commit 2']
|
|
||||||
|
|
||||||
# Test function returns True when there are commits
|
|
||||||
assert (
|
|
||||||
has_commits_on_branch(self.cwd, self.base_branch, self.current_branch)
|
|
||||||
is True
|
|
||||||
)
|
|
||||||
|
|
||||||
# Verify get_commit_messages was called with correct arguments
|
|
||||||
mock_get_commit_messages.assert_called_once_with(
|
|
||||||
self.cwd, self.base_branch, self.current_branch,
|
|
||||||
)
|
|
||||||
|
|
||||||
@patch('aider_gitea.get_commit_messages')
|
|
||||||
def test_has_commits_false(self, mock_get_commit_messages):
|
|
||||||
# Setup mock to return empty list
|
|
||||||
mock_get_commit_messages.return_value = []
|
|
||||||
|
|
||||||
# Test function returns False when there are no commits
|
|
||||||
assert (
|
|
||||||
has_commits_on_branch(self.cwd, self.base_branch, self.current_branch)
|
|
||||||
is False
|
|
||||||
)
|
|
||||||
|
|
||||||
# Verify get_commit_messages was called with correct arguments
|
|
||||||
mock_get_commit_messages.assert_called_once_with(
|
|
||||||
self.cwd, self.base_branch, self.current_branch,
|
|
||||||
)
|
|
||||||
|
|
||||||
@patch('aider_gitea.get_commit_messages')
|
|
||||||
def test_has_commits_exception(self, mock_get_commit_messages):
|
|
||||||
# Setup mock to raise an exception
|
|
||||||
mock_get_commit_messages.side_effect = Exception('Git command failed')
|
|
||||||
|
|
||||||
# Test function returns False when an exception occurs
|
|
||||||
assert (
|
|
||||||
has_commits_on_branch(self.cwd, self.base_branch, self.current_branch)
|
|
||||||
is False
|
|
||||||
)
|
|
Loading…
Reference in New Issue
Block a user