Exemple #1
0
    def test_update_repository_directory_is_not_repository(self, mocker):
        mocker.patch.object(io, "exists", return_value=True)
        mocker.patch.object(io, "remove")
        mocker.patch.object(
            io,
            "execute",
            side_effect=[
                subprocess.CalledProcessError(1, "git remote get-url origin"),
                "",
                "",
            ],
        )

        git.update_repository("/path_to/a_git_repository",
                              "[email protected]:org/repo.git")

        io.exists.assert_called_once_with("/path_to/a_git_repository")
        io.remove.assert_called_once_with("/path_to/a_git_repository")
        io.execute.assert_has_calls([
            call("git remote get-url origin", "/path_to/a_git_repository"),
            call(
                "git clone [email protected]:org/repo.git /path_to/a_git_repository"
            ),
            call("git reset --hard origin/master",
                 "/path_to/a_git_repository"),
        ])
Exemple #2
0
    def test_update_repository_clone_if_not_existing_default_revision(self, io_mock):
        io_mock.exists.return_value = False
        io_mock.execute.side_effect = ["", ""]

        git.update_repository("/path_to/a_git_repository", "[email protected]:org/repo.git")

        io_mock.exists.assert_called_once_with("/path_to/a_git_repository")
        io_mock.execute.assert_has_calls(
            [
                call("git clone [email protected]:org/repo.git /path_to/a_git_repository"),
                call("git reset --hard origin/master", "/path_to/a_git_repository"),
            ]
        )
Exemple #3
0
    def test_update_repository_remote_match_update(self, io_mock):
        io_mock.exists.return_value = True
        io_mock.execute.side_effect = ["[email protected]:org/repo.git", "", "", ""]

        git.update_repository("/path_to/a_git_repository", "[email protected]:org/repo.git")

        io_mock.exists.assert_called_once_with("/path_to/a_git_repository")
        io_mock.execute.assert_has_calls(
            [
                call("git remote get-url origin", "/path_to/a_git_repository"),
                call("git clean -dfx", "/path_to/a_git_repository"),
                call("git fetch --all", "/path_to/a_git_repository"),
                call("git reset --hard origin/master", "/path_to/a_git_repository"),
            ]
        )
Exemple #4
0
    def test_update_repository_clone_if_not_existing_branch_revision(
            self, mocker):
        mocker.patch.object(io, "exists", return_value=False)
        mocker.patch.object(io, "execute", side_effect=["", ""])

        git.update_repository("/path_to/a_git_repository",
                              "[email protected]:org/repo.git", "feature/branch")

        io.exists.assert_called_once_with("/path_to/a_git_repository")
        io.execute.assert_has_calls([
            call(
                "git clone [email protected]:org/repo.git /path_to/a_git_repository"
            ),
            call("git reset --hard feature/branch",
                 "/path_to/a_git_repository"),
        ])
Exemple #5
0
    def test_update_repository_directory_is_not_repository(self, io_mock):
        io_mock.exists.return_value = True
        io_mock.execute.side_effect = [
            subprocess.CalledProcessError(1, "git remote get-url origin"),
            "",
            "",
        ]

        git.update_repository("/path_to/a_git_repository", "[email protected]:org/repo.git")

        io_mock.exists.assert_called_once_with("/path_to/a_git_repository")
        io_mock.remove.assert_called_once_with("/path_to/a_git_repository")
        io_mock.execute.assert_has_calls(
            [
                call("git remote get-url origin", "/path_to/a_git_repository"),
                call("git clone [email protected]:org/repo.git /path_to/a_git_repository"),
                call("git reset --hard origin/master", "/path_to/a_git_repository"),
            ]
        )
Exemple #6
0
    def test_update_repository_remote_mismatch(self, mocker):
        mocker.patch.object(io, "exists", return_value=True)
        mocker.patch.object(
            io, "execute", side_effect=["[email protected]:org/repo.git", "", ""])
        mocker.patch.object(io, "remove")

        git.update_repository("/path_to/a_git_repository",
                              "[email protected]:org/another_repo_url.git")

        io.exists.assert_called_once_with("/path_to/a_git_repository")
        io.remove.assert_called_once_with("/path_to/a_git_repository")
        io.execute.assert_has_calls([
            call("git remote get-url origin", "/path_to/a_git_repository"),
            call(
                "git clone [email protected]:org/another_repo_url.git /path_to/a_git_repository"
            ),
            call("git reset --hard origin/master",
                 "/path_to/a_git_repository"),
        ])