From: Thomas Bechtold Date: Fri, 1 Nov 2019 08:13:04 +0000 (+0100) Subject: Fix fetch_branch() check for BranchNotFoundError with newer git X-Git-Tag: 1.1.0~205^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fpull%2F1342%2Fhead;p=teuthology.git Fix fetch_branch() check for BranchNotFoundError with newer git With newer git versions, the string when a branch is not found is lower case[1]. This fixes the test TestRepoUtils.test_fetch_branch_fake_branch which was failing due to this problem. [1] https://github.com/git/git/commit/0b9c3afdbfb629363 --- diff --git a/teuthology/repo_utils.py b/teuthology/repo_utils.py index bcff53af..cfcacbba 100644 --- a/teuthology/repo_utils.py +++ b/teuthology/repo_utils.py @@ -199,10 +199,10 @@ def fetch_branch(repo_path, branch, shallow=True): 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!") diff --git a/teuthology/test/test_repo_utils.py b/teuthology/test/test_repo_utils.py index 9ee0aed6..c87453f0 100644 --- a/teuthology/test/test_repo_utils.py +++ b/teuthology/test/test_repo_utils.py @@ -1,4 +1,5 @@ import logging +import mock import os import os.path from pytest import raises, mark @@ -92,6 +93,26 @@ class TestRepoUtils(object): 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')