예제 #1
0
    def test_update_local_stashes_local_changes(self, platform_url,
                                                with_student_repos, tmp_path):
        """Test that updating local repositories with unstaged changes causes
        the changes to be stashed, and the update to proceed.
        """
        new_file_name = "suspicious_file.txt"
        target_repo = funcs.get_repos(platform_url)[-1]
        self._clone_all_student_repos(platform_url, tmp_path)

        # update remote repo
        with funcs.update_repository(target_repo.url) as repo_path:
            (repo_path / new_file_name).write_text(new_file_name)
        # update local repo
        local_repo_path = list(tmp_path.rglob(target_repo.name))[0]
        next(file for file in local_repo_path.iterdir()
             if file.is_file()).write_text("this is an update!")

        # act
        funcs.run_repobee(
            f"repos clone -a {const.TEMPLATE_REPOS_ARG} "
            f"--update-local "
            f"--base-url {platform_url}",
            workdir=tmp_path,
        )

        # assert
        assert local_repo_path.parent.parent == tmp_path
        local_new_file = local_repo_path / new_file_name
        assert local_new_file.is_file()
        assert local_new_file.read_text() == new_file_name
        assert git.Repo(local_repo_path).git.stash("list")
예제 #2
0
    def test_does_not_update_local_by_default(self, platform_url,
                                              with_student_repos, tmp_path,
                                              capsys):
        """Test that cloning an update repository that exists locally does not
        cause it to be updated by default.
        """
        # arrange
        new_file_name = "suspicious_file.txt"
        target_repo = funcs.get_repos(platform_url)[-1]
        self._clone_all_student_repos(platform_url, tmp_path)

        with funcs.update_repository(target_repo.url) as repo_path:
            (repo_path / new_file_name).write_text(new_file_name)

        # act
        funcs.run_repobee(
            f"repos clone -a {const.TEMPLATE_REPOS_ARG} "
            f"--base-url {platform_url}",
            workdir=tmp_path,
        )

        # assert
        local_repo_path = list(tmp_path.rglob(target_repo.name))[0]
        local_new_file = local_repo_path / new_file_name
        assert not local_new_file.is_file()
        assert "--update-local" in capsys.readouterr().err
예제 #3
0
    def test_update_local(self, platform_url, with_student_repos, tmp_path):
        """Test cloning an updated repository that already exists locally, when
        there are no incompatible changes between the remote copy and the local
        copy and --update-local is specified.
        """
        # arrange
        new_file_name = "suspicious_file.txt"
        target_repo = funcs.get_repos(platform_url)[-1]
        self._clone_all_student_repos(platform_url, tmp_path)

        with funcs.update_repository(target_repo.url) as repo_path:
            (repo_path / new_file_name).write_text(new_file_name)

        # act
        funcs.run_repobee(
            f"repos clone -a {const.TEMPLATE_REPOS_ARG} "
            f"--update-local "
            f"--base-url {platform_url}",
            workdir=tmp_path,
        )

        # assert
        local_repo_path = list(tmp_path.rglob(target_repo.name))[0]
        assert local_repo_path.parent.parent == tmp_path
        local_new_file = local_repo_path / new_file_name
        assert local_new_file.is_file()
        assert local_new_file.read_text() == new_file_name