def test_clone_git_shallow_revision(self): path, revision = create_local_git_repo({"myfile": "contents"}, commits=3, tags=["1.0"], branch="develop") tmp = temp_folder() git = Git(tmp) if Git.get_version() < "2.13": # older Git versions have known bugs with "git fetch origin <sha>": # https://github.com/git/git/blob/master/Documentation/RelNotes/2.13.0.txt # * "git fetch" that requests a commit by object name, when the other # side does not allow such an request, failed without much # explanation. # https://github.com/git/git/blob/master/Documentation/RelNotes/2.14.0.txt # * There is no good reason why "git fetch $there $sha1" should fail # when the $sha1 names an object at the tip of an advertised ref, # even when the other side hasn't enabled allowTipSHA1InWant. with self.assertRaises(subprocess.CalledProcessError): git.clone("file://" + path, branch=revision, shallow=True) else: git.clone("file://" + path, branch=revision, shallow=True) with self.assertRaises(subprocess.CalledProcessError): git.checkout(element="HEAD~1") self.assertTrue(os.path.exists(os.path.join(tmp, "myfile"))) self.assertEqual(git.get_revision(), revision) self.assertEqual(git.run("rev-list --all --count"), "1")
def test_version_invalid(self, mocked_open): mocked_open.return_value.communicate.return_value = ('failed'.encode(), None) with self.assertRaises(ConanException): Git.get_version()
def test_version(self, mocked_open): mocked_open.return_value.communicate.return_value = ( 'git version 2.21.0'.encode(), None) version = Git.get_version() self.assertEqual(version, "2.21.0")