]> git.apps.os.sepia.ceph.com Git - teuthology.git/commitdiff
Fix fetch_branch() check for BranchNotFoundError with newer git 1342/head
authorThomas Bechtold <tbechtold@suse.com>
Fri, 1 Nov 2019 08:13:04 +0000 (09:13 +0100)
committerThomas Bechtold <tbechtold@suse.com>
Tue, 5 Nov 2019 07:55:57 +0000 (08:55 +0100)
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

teuthology/repo_utils.py
teuthology/test/test_repo_utils.py

index bcff53af906102b85800d013be541319c8dedcd7..cfcacbba824a66266ba214a85bed4df2c63e182e 100644 (file)
@@ -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!")
index 9ee0aed691d471b69887970ac1f27d17d01b8477..c87453f0a0ca5470347c30eacdd89c09204b1eb3 100644 (file)
@@ -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')