Exemplo n.º 1
0
    def test_creation_and_removal(self, bare_rw_repo):
        new_name = "test_new_one"
        arg_list = (new_name, "git@server:hello.git")
        remote = Remote.create(bare_rw_repo, *arg_list)
        assert remote.name == "test_new_one"
        assert remote in bare_rw_repo.remotes
        assert remote.exists()

        # create same one again
        self.failUnlessRaises(GitCommandError, Remote.create, bare_rw_repo,
                              *arg_list)

        Remote.remove(bare_rw_repo, new_name)
        assert remote.exists(
        )  # We still have a cache that doesn't know we were deleted by name
        remote._clear_cache()
        assert not remote.exists(
        )  # Cache should be renewed now. This is an issue ...

        for remote in bare_rw_repo.remotes:
            if remote.name == new_name:
                raise AssertionError("Remote removal failed")
            # END if deleted remote matches existing remote's name
        # END for each remote

        # Issue #262 - the next call would fail if bug wasn't fixed
        bare_rw_repo.create_remote('bogus', '/bogus/path', mirror='push')
Exemplo n.º 2
0
def backup_user_repos(git, local, max_size, topic, udir, redo, uname, uemail):
    logger = logging.getLogger('user-repos')
    for repo in git.get_own_user_repos():

        repo_dir = local.get_path(repo['name'])
        if udir:
            repo_dir = local.get_path(repo, repo['owner']['login'])

        if os.path.exists(repo_dir) and redo:
            # Remove the repo dir so it can be re-created.
            shutil.rmtree(repo_dir)

        res = backup_repo(local, repo, logger, max_size, topic,
                          repo['owner']['login'] if udir else None)

        # Change author/committer ID information if specified.
        if res and uname and uemail:
            cmd = [
                'git', 'filter-branch', '-f', '--env-filter',
                "GIT_AUTHOR_NAME='{}'; GIT_AUTHOR_EMAIL='{}'; GIT_COMMITTER_NAME='{}'; GIT_COMMITTER_EMAIL='{}';"
                .format(uname, uemail, uname, uemail), '--', '--all'
            ]
            proc = subprocess.Popen(cmd, cwd=repo_dir, stdout=subprocess.PIPE)

            git_std = proc.communicate()
            for line in git_std:
                if line:
                    logger.info('{}: {}'.format(repo['name'], line.strip()))

            # Prune all remotes to sterilize.
            r = Repo(repo_dir)
            for remote in r.remotes:
                Remote.remove(r, remote.name)
Exemplo n.º 3
0
    def _push_branch(self) -> None:
        """Push the u/neophile branch to GitHub.

        Raises
        ------
        neophile.exceptions.PushError
            Pushing the branch to GitHub failed.
        """
        branch = self._repo.head.ref.name
        remote_url = self._get_authenticated_remote()
        remote = Remote.add(self._repo, "tmp-neophile", remote_url)
        try:
            push_info = remote.push(f"{branch}:{branch}", force=True)
            for result in push_info:
                if result.flags & PushInfo.ERROR:
                    msg = f"Pushing {branch} failed: {result.summary}"
                    raise PushError(msg)
        finally:
            Remote.remove(self._repo, "tmp-neophile")
Exemplo n.º 4
0
    def test_creation_and_removal(self, bare_rw_repo):
        new_name = "test_new_one"
        arg_list = (new_name, "git@server:hello.git")
        remote = Remote.create(bare_rw_repo, *arg_list)
        assert remote.name == "test_new_one"
        assert remote in bare_rw_repo.remotes
        assert remote.exists()

        # create same one again
        self.failUnlessRaises(GitCommandError, Remote.create, bare_rw_repo, *arg_list)

        Remote.remove(bare_rw_repo, new_name)
        assert remote.exists()      # We still have a cache that doesn't know we were deleted by name
        remote._clear_cache()
        assert not remote.exists()  # Cache should be renewed now. This is an issue ...

        for remote in bare_rw_repo.remotes:
            if remote.name == new_name:
                raise AssertionError("Remote removal failed")
Exemplo n.º 5
0
    def test_creation_and_removal(self, bare_rw_repo):
        new_name = "test_new_one"
        arg_list = (new_name, "git@server:hello.git")
        remote = Remote.create(bare_rw_repo, *arg_list)
        assert remote.name == "test_new_one"
        assert remote in bare_rw_repo.remotes
        assert remote.exists()

        # create same one again
        self.failUnlessRaises(GitCommandError, Remote.create, bare_rw_repo, *arg_list)

        Remote.remove(bare_rw_repo, new_name)
        assert remote.exists()      # We still have a cache that doesn't know we were deleted by name
        remote._clear_cache()
        assert not remote.exists()  # Cache should be renewed now. This is an issue ...

        for remote in bare_rw_repo.remotes:
            if remote.name == new_name:
                raise AssertionError("Remote removal failed")
Exemplo n.º 6
0
    def test_creation_and_removal(self, bare_rw_repo):
        new_name = "test_new_one"
        arg_list = (new_name, "git@server:hello.git")
        remote = Remote.create(bare_rw_repo, *arg_list)
        assert remote.name == "test_new_one"
        assert remote in bare_rw_repo.remotes
        assert remote.exists()

        # create same one again
        self.failUnlessRaises(GitCommandError, Remote.create, bare_rw_repo, *arg_list)

        Remote.remove(bare_rw_repo, new_name)
        assert remote.exists()      # We still have a cache that doesn't know we were deleted by name
        remote._clear_cache()
        assert not remote.exists()  # Cache should be renewed now. This is an issue ...

        for remote in bare_rw_repo.remotes:
            if remote.name == new_name:
                raise AssertionError("Remote removal failed")
            # END if deleted remote matches existing remote's name
        # END for each remote

        # Issue #262 - the next call would fail if bug wasn't fixed
        bare_rw_repo.create_remote('bogus', '/bogus/path', mirror='push')