def remote(self, name='origin'): """:return: Remote with the specified name :raise ValueError: if no remote with such a name exists""" r = Remote(self, name) if not r.exists(): raise ValueError("Remote named '%s' didn't exist" % name) return r
def fetch_repo(self, url, branch): if os.path.exists(".git"): gc.collect() repo = git.Repo(getcwd()) repo.git.clear_cache() rmtree(repo.git_dir) self.repo = git.Repo.init(getcwd()) r = Remote(self.repo, name="origin") if r in Remote.list_items(self.repo): self.repo.delete_remote(r) self.repo.git.remote("add", "origin", url) self.repo.git.fetch("origin", "-t") remote_branch = self.check_remote_branch() if not remote_branch: print("Fetch tag failed, just fetch all the source code") self.repo.git.fetch("origin") remote_branch = self.check_remote_branch() if not remote_branch: print("No branch found in the remote repo, patch failed") shutil.rmtree(".git") return False self.repo.git.checkout(remote_branch, "--force", b="master") print( "Branch 'master' set up to track remote branch '{}' from 'origin'". format(remote_branch)) self.check_commit() self.repo.git.checkout(self.commit, "--force", b=branch) print("Switched to a new branch '{}'".format(branch))
def create_remote(self, name, url, **kwargs): """Create a new remote. For more information, please see the documentation of the Remote.create methods :return: Remote reference""" return Remote.create(self, name, url, **kwargs)
def delete_remote(self, remote): """Delete the given remote.""" return Remote.remove(self, remote)
def remotes(self): """A list of Remote objects allowing to access and manipulate remotes :return: ``git.IterableList(Remote, ...)``""" return Remote.list_items(self)
def remote(self, name='origin'): """:return: Remote with the specified name :raise ValueError: if no remote with such a name exists""" return Remote(self, name)
def delete_remote(self, remote: 'Remote') -> str: """Delete the given remote.""" return Remote.remove(self, remote)