def fetch(self, prune: bool = False, prune_tags: bool = False, tags: bool = False, depth: Optional[int] = None, remote: Optional[str] = None, branch: Optional[str] = None, unshallow: bool = False, jobs: Optional[int] = None, fetch_all: bool = False, check: bool = True, print_output: bool = True): # FIXME: Consolidate this implementation with the one for Remotes CONSOLE.stdout(f' - Fetch repo') try: GitOnline.fetch(self.path, remote=remote, prune=prune, prune_tags=prune_tags, tags=tags, depth=depth, branch=branch, unshallow=unshallow, jobs=jobs, fetch_all=fetch_all, print_output=print_output) except Exception: # noqa message = f'Failed to fetch repo' if check: GIT_LOG.error(message) raise CONSOLE.stdout(message)
def fetch(self, prune: bool = False, prune_tags: bool = False, tags: bool = False, depth: Optional[int] = None, branch: Optional[str] = None, unshallow: bool = False, jobs: Optional[int] = None, fetch_all: bool = False, check: bool = True, print_output: bool = True) -> None: output = self.name if branch is not None: branch = branch output = f'{output} {branch}' CONSOLE.stdout(f'Fetch from {output}') try: GitOnline.fetch(self.path, remote=self.name, prune=prune, prune_tags=prune_tags, tags=tags, depth=depth, branch=branch, unshallow=unshallow, jobs=jobs, fetch_all=fetch_all, print_output=print_output) except Exception: # noqa message = f'Failed to fetch from {output}' if check: GIT_LOG.error(message) raise CONSOLE.stdout(f' - {message}')
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 create(self) -> None: if GitOffline.has_tracking_branch(self.path, self.local_branch.name): CONSOLE.stdout(' - Tracking branch already exists') return # TODO: Add Format util to format tracking branch output: local_branch -> remote remote_branch CONSOLE.stdout( f' - Create tracking branch {Format.Git.ref(self.name)}') GitOnline.fetch(self.path, prune=True) # local and remote branches exist if self.local_branch.exists and self.upstream_branch.exists: self.set_upstream() return # only local branch exists if self.local_branch.exists: # GitOnline.push(self.path, # local_branch=self.name, # remote_branch=self.upstream_branch.name, # remote=self.upstream_branch.remote.name, # set_upstream=True) self.upstream_branch.create(branch=self.local_branch.name) self.set_upstream() GitOnline.fetch(self.path, prune=True) return # only remote branch exists if self.upstream_branch.exists: self.local_branch.create(branch=self.upstream_branch.name, remote=self.upstream_branch.remote.name) # GitOffline.create_local_branch(self.path, self.name, # branch=self.upstream_branch.name, # remote=self.upstream_branch.remote) return # local and remote branches DO NOT exist self.upstream_branch.create() GitOnline.fetch(self.path, prune=True) self.local_branch.create(branch=self.upstream_branch.name, remote=self.upstream_branch.remote.name)