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 remotes(self): """A list of Remote objects allowing to access and manipulate remotes :return: ``git.IterableList(Remote, ...)``""" return Remote.list_items(self)