stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
if proc.wait() != 0:
- not_found_str = "fatal: Couldn't find remote ref %s" % branch
+ not_found_str = "fatal: couldn't find remote ref %s" % branch
out = proc.stdout.read()
log.error(out)
- if not_found_str in out:
+ if not_found_str in out.lower():
raise BranchNotFoundError(branch)
else:
raise GitError("git fetch failed!")
import logging
+import mock
import os
import os.path
from pytest import raises, mark
with raises(BranchNotFoundError):
repo_utils.fetch_branch(self.dest_path, 'nobranch')
+ @mark.parametrize('git_str',
+ ["fatal: couldn't find remote ref",
+ "fatal: Couldn't find remote ref"])
+ @mock.patch('subprocess.Popen')
+ def test_fetch_branch_different_git_versions(self, mock_popen, git_str):
+ """
+ Newer git versions return a lower case string
+ See: https://github.com/git/git/commit/0b9c3afdbfb629363
+ """
+ branch_name = 'nobranch'
+ process_mock = mock.Mock()
+ attrs = {
+ 'wait.return_value': 1,
+ 'stdout.read.return_value': "%s %s" % (git_str, branch_name),
+ }
+ process_mock.configure_mock(**attrs)
+ mock_popen.return_value = process_mock
+ with raises(BranchNotFoundError):
+ repo_utils.fetch_branch('', branch_name)
+
def test_enforce_existing_branch(self):
repo_utils.enforce_repo_state(self.repo_url, self.dest_path,
'master')