def get_remote_branch(self, branch: str, remote: Optional[str] = None, url: Optional[str] = None, online: bool = False) -> Optional[RemoteBranch]: remote = ORIGIN if remote is None else remote from pygoodle.git.model.factory import GitFactory if online or url is not None: return GitFactory.get_remote_branch_online(self.path, branch=branch, remote=remote, url=url) return GitFactory.get_remote_branch_offline(self.path, branch=branch, remote=remote)
def get_remote_tag(self, tag: str, remote: Optional[str] = None, url: Optional[str] = None) -> Optional[RemoteTag]: remote = ORIGIN if remote is None else remote from pygoodle.git.model.factory import GitFactory return GitFactory.get_remote_tag(self.path, tag, remote, url=url)
def delete(self) -> None: from pygoodle.git.model.factory import GitFactory if not GitFactory.has_remote_branch_online(self.path, self.name, self.remote.name): CONSOLE.stdout( f" - Remote branch {Format.Git.ref(self.name)} doesn't exist") return CONSOLE.stdout(f' - Delete remote branch {Format.Git.ref(self.name)}') GitOnline.delete_remote_branch(self.path, branch=self.name, remote=self.remote.name, force=True)
def get_remote(self, remote: Optional[str] = None, fetch_url: Optional[str] = None, push_url: Optional[str] = None) -> Optional[Remote]: from pygoodle.git.model.factory import GitFactory remotes = GitFactory.get_remotes(self.path) if remote is not None: remotes = [r for r in remotes if r.name == remote] if fetch_url is not None: remotes = [r for r in remotes if r.fetch_url == fetch_url] if push_url is not None: remotes = [r for r in remotes if r.push_url == push_url] return remotes[0] if remotes else None
def create(self, branch: Optional[str] = None, remote: Optional[str] = None) -> None: from pygoodle.git.model.factory import GitFactory if GitFactory.has_remote_branch_online(self.path, self.name, self.remote.name): CONSOLE.stdout( f' - Remote branch {Format.Git.ref(self.name)} already exists') return CONSOLE.stdout(f' - Create remote branch {Format.Git.ref(self.name)}') branch = self.name if branch is None else branch from pygoodle.git.model.branch.local_branch import LocalBranch local_branch = LocalBranch(self.path, branch) GitOnline.fetch(self.path, prune=True) has_existing_branch = local_branch.exists if not has_existing_branch: local_branch.create(branch=branch, remote=remote) local_branch.push(remote=self.remote.name, branch=self.name) if not has_existing_branch: GitOffline.delete_local_branch(self.path, branch) GitOnline.fetch(self.path, prune=True)
def exists(self) -> bool: from pygoodle.git.model.factory import GitFactory return GitFactory.has_local_branch(self.path, self.name)
def remote(self, name: str) -> Optional[Remote]: from pygoodle.git.model.factory import GitFactory return GitFactory.get_remote(self.path, name)
def is_tracking_branch(self) -> bool: from pygoodle.git.model.factory import GitFactory branches = GitFactory.get_tracking_branches(self.path) return any([branch.name == self.name for branch in branches])
def get_all_branches(self, online: bool = False) -> 'AllBranches': from pygoodle.git.model.factory import GitFactory return GitFactory.get_all_branches(self.path, online=online)
def get_diff(self) -> 'Diff': from pygoodle.git.model.factory import GitFactory return GitFactory.get_diff(self.path)
def exists(self) -> bool: from pygoodle.git.model.factory import GitFactory return GitFactory.has_remote_tag(self.path, self.name, self.remote.name)
def exists_online(self, url: Optional[str] = None) -> bool: from pygoodle.git.model.factory import GitFactory return GitFactory.has_remote_branch_online(self.path, branch=self.name, remote=self.remote.name, url=url)
def get_local_tags(self) -> List[LocalTag]: from pygoodle.git.model.factory import GitFactory return GitFactory.get_local_tags(self.path)
def get_local_tag(self, tag: str) -> Optional[LocalTag]: from pygoodle.git.model.factory import GitFactory return GitFactory.get_local_tag(self.path, tag)
def get_local_branches(self) -> List[LocalBranch]: from pygoodle.git.model.factory import GitFactory return GitFactory.get_local_branches(self.path)
def get_local_branch(self, branch: str) -> Optional[LocalBranch]: from pygoodle.git.model.factory import GitFactory return GitFactory.get_local_branch(self.path, branch)
def get_submodule(self, submodule_path: Path) -> Optional['Submodule']: from pygoodle.git.model.factory import GitFactory return GitFactory.get_submodule(self.path, submodule_path)
def is_tracking_branch(self) -> bool: from pygoodle.git.model.factory import GitFactory return GitFactory.has_tracking_branch(self.path, self.name)
def get_submodules(self) -> List['Submodule']: from pygoodle.git.model.factory import GitFactory return GitFactory.get_submodules(self.path)
def get_tracking_branches(self) -> List[TrackingBranch]: from pygoodle.git.model.factory import GitFactory return GitFactory.get_tracking_branches(self.path)
def get_tracking_branch( self, branch: str, remote: Optional[str] = None) -> Optional[TrackingBranch]: from pygoodle.git.model.factory import GitFactory return GitFactory.get_tracking_branch(self.path, branch, remote=remote)
def branches(self, url: Optional[str] = None, online: bool = False) -> List[RemoteBranch]: from pygoodle.git.model.factory import GitFactory if online or url is not None: return GitFactory.get_remote_branches_online(self.path, remote=self.name, url=url) return GitFactory.get_remote_branches_offline(self.path, self.name)
def get_remote_branches(self, online: bool = False) -> List[RemoteBranch]: from pygoodle.git.model.factory import GitFactory return GitFactory.get_all_remote_branches(self.path, online=online)
def exists_online(self, url: str) -> bool: from pygoodle.git.model.factory import GitFactory return GitFactory.has_remote_tag(self.path, tag=self.name, remote=self.remote.name, url=url)
def get_remotes(self) -> List[Remote]: from pygoodle.git.model.factory import GitFactory return GitFactory.get_remotes(self.path)