def _sync_manifest(self, local_manifest): """ Update the local manifest clone with the remote """ manifest_repo = os.path.join(self.manifests_root, local_manifest.name) git = qisrc.git.Git(manifest_repo) with git.transaction() as transaction: git.fetch("origin") git.checkout("-B", local_manifest.branch) git.reset("--hard", "origin/%s" % local_manifest.branch) if not transaction.ok: ui.warning("Update failed") ui.info(transaction.output) return
def clever_reset_ref(git_project, ref, raises=True): """ Resets only if needed, fetches only if needed """ try: remote_name = git_project.default_remote.name except AttributeError: error_msg = "Project {} has no default remote, defaulting to origin" ui.error(error_msg.format(git_project.name)) remote_name = "origin" git = qisrc.git.Git(git_project.path) if ref.startswith("refs/"): if raises: git.fetch(remote_name, ref) git.reset("--hard", "FETCH_HEAD") return else: with git.tansaction() as transaction: git.fetch(remote_name, ref) git.reset("--hard", "FETCH_HEAD") return transaction.ok, transaction.output rc, ref_sha1 = git.call("rev-parse", ref, raises=False) if rc != 0: # Maybe this is a newly pushed tag, try to fetch: git.fetch(remote_name) rc, ref_sha1 = git.call("rev-parse", ref, raises=False) if rc != 0: return False, "Could not parse %s as a valid ref" % ref _, actual_sha1 = git.call("rev-parse", "HEAD", raises=False) if actual_sha1 == ref_sha1: # Nothing to do if raises: return else: return True, "" ret, _ = git.call("show", "--oneline", ref, raises=False) if ret == 0: # SHA-1 exists locally if raises: git.reset("--hard", ref) else: rc, out = git.reset("--hard", ref, raises=False) return (rc == 0), out else: # Full fetch in this case if raises: git.fetch(remote_name) git.reset("--hard", ref) else: with git.transaction() as transaction: git.fetch(remote_name) git.reset("--hard", ref) return transaction.ok, transaction.output
def _sync_git(repo, url, branch, ref): git = qisrc.git.Git(repo) git.set_remote("origin", url) if git.get_current_branch() != branch: git.checkout("-B", branch) with git.transaction() as transaction: git.fetch("origin") if ref: to_reset = ref git.reset("--hard", to_reset) else: git.reset("--hard", "origin/%s" % branch) if not transaction.ok: raise Exception("Update failed\n" + transaction.output)
def _sync_manifest(self): """ Update the local manifest clone with the remote """ git = qisrc.git.Git(self.manifest_repo) git.set_remote("origin", self.manifest.url) if git.get_current_branch() != self.manifest.branch: git.checkout("-B", self.manifest.branch) with git.transaction() as transaction: git.fetch("origin") if self.manifest.ref: to_reset = self.manifest.ref git.reset("--hard", to_reset) else: git.reset("--hard", "origin/%s" % self.manifest.branch) if not transaction.ok: raise Exception("Update failed\n" + transaction.output)
def _sync_manifest(self): """ Update the local manifest clone with the remote """ if not self.manifest.url: mess = """ \ No manifest set for worktree in {root} Please run `qisrc init MANIFEST_URL` """ raise Exception(mess.format(root=self.git_worktree.root)) git = qisrc.git.Git(self.manifest_repo) git.set_remote("origin", self.manifest.url) if git.get_current_branch() != self.manifest.branch: git.checkout("-B", self.manifest.branch) with git.transaction() as transaction: git.fetch("origin") if self.manifest.ref: to_reset = self.manifest.ref git.reset("--hard", to_reset) else: git.reset("--hard", "origin/%s" % self.manifest.branch) if not transaction.ok: raise Exception("Update failed\n" + transaction.output)