Ejemplo n.º 1
0
    def push(self, *args):
        force_flag, remote_name, refspec = args

        assert force_flag in ('', '--force')

        branch, remote_branch = refspec.split(':')
        remote_url = self._remotes[remote_name]
        remote_repo = self.remote_repos[remote_url]

        old_sha = remote_repo.get_ref(remote_branch)
        new_sha = self._local_repo.get_ref(branch)

        if force_flag:
            remote_repo.set_ref(remote_branch, new_sha)
        else:
            expected_remote_sha = self._remote_refs[remote_name].get_ref(remote_branch)
            if old_sha != expected_remote_sha:
                raise git.GitError("conflict: can't push")
            remote_repo.set_ref(remote_branch, new_sha)

        for callback in self.on_push_callbacks:
            callback(
                remote_url=remote_url,
                remote_branch=remote_branch,
                old_sha=old_sha,
                new_sha=new_sha,
            )
Ejemplo n.º 2
0
    def remote(self, *args):
        action = args[0]
        if action == 'rm':
            _, remote = args
            try:
                self._remotes.pop(remote)
            except KeyError:
                raise git.GitError('No such remote: %s' % remote)

        elif action == 'add':
            _, remote, url = args
            self._remotes[remote] = url
        else:
            assert False, args