def _maybe_print_old_git_warning(script_path: str) -> None: """If our script is running in a Git repo, and we're running a very old Git version, print a warning that Git integration will be unavailable. """ repo = GitRepo(script_path) if ( not repo.is_valid() and repo.git_version is not None and repo.git_version < MIN_GIT_VERSION ): git_version_string = ".".join(str(val) for val in repo.git_version) min_version_string = ".".join(str(val) for val in MIN_GIT_VERSION) click.secho("") click.secho(" Git integration is disabled.", fg="yellow", bold=True) click.secho("") click.secho( f" Streamlit requires Git {min_version_string} or later, " f"but you have {git_version_string}.", fg="yellow", ) click.secho( " Git is used by Streamlit Cloud (https://streamlit.io/cloud).", fg="yellow", ) click.secho(" To enable this feature, please update Git.", fg="yellow")
def test_git_repo_valid(self): with patch("git.repo.base.Repo.GitCommandWrapperType") as git_mock, patch( "streamlit.git_util.os" ): git_mock.return_value.version_info = (2, 20, 3) # A recent git version repo = GitRepo(".") self.assertTrue(repo.is_valid()) self.assertEqual((2, 20, 3), repo.git_version)
def test_old_git_version(self): """If the installed git is older than 2.7, certain repo operations prompt the user for credentials. We don't want to do this, so repo.is_valid() returns False for old gits. """ with patch("git.repo.base.Repo.GitCommandWrapperType") as git_mock, patch( "streamlit.git_util.os" ): git_mock.return_value.version_info = (1, 6, 4) # An old git version repo = GitRepo(".") self.assertFalse(repo.is_valid()) self.assertEqual((1, 6, 4), repo.git_version)
def test_git_repo_invalid(self): with patch("git.Repo") as mock: mock.side_effect = InvalidGitRepositoryError("Not a git repo") repo = GitRepo(".") self.assertFalse(repo.is_valid())
def test_git_repo_valid(self): with patch("git.Repo") as mock, patch("os.path"): mock.git.return_value = MagicMock() repo = GitRepo(".") self.assertTrue(repo.is_valid())