Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _reset_manifest_clone(self, url: str, *, branch: str) -> None:
tsrc.git.run(self.clone_path, "remote", "set-url", "origin", url)
tsrc.git.run(self.clone_path, "fetch")
tsrc.git.run(self.clone_path, "checkout", "-B", branch)
# fmt: off
tsrc.git.run(
self.clone_path, "branch", branch,
"--set-upstream-to", "origin/%s" % branch
)
# fmt: on
ref = "origin/%s" % branch
tsrc.git.run(self.clone_path, "reset", "--hard", ref)
def reset_repo(self, repo: tsrc.Repo) -> None:
repo_path = self.workspace_path / repo.src
ref = repo.sha1
if ref:
ui.info_2("Resetting", repo.src, "to", ref)
try:
tsrc.git.run(repo_path, "reset", "--hard", ref)
except tsrc.Error:
raise tsrc.Error("Resetting to", ref, "failed")
def fetch(self, repo: tsrc.Repo) -> None:
repo_path = self.workspace_path / repo.src
for remote in repo.remotes:
try:
ui.info_2("Fetching", remote.name)
cmd = ["fetch", "--tags", "--prune", remote.name]
if self.force:
cmd.append("--force")
tsrc.git.run(repo_path, *cmd)
except tsrc.Error:
raise tsrc.Error("fetch from %s failed" % remote.name)
def _clone_manifest(self, url: str, *, branch: str) -> None:
parent, name = self.clone_path.splitpath()
parent.makedirs_p()
tsrc.git.run(self.clone_path.parent, "clone", url, "--branch", branch, name)
def sync_repo_to_ref(repo_path: Path, ref: str) -> None:
ui.info_2("Resetting to", ref)
status = tsrc.git.get_status(repo_path)
if status.dirty:
raise tsrc.Error("%s is dirty, skipping" % repo_path)
try:
tsrc.git.run(repo_path, "reset", "--hard", ref)
except tsrc.Error:
raise tsrc.Error("updating ref failed")
def set_remote(self, repo: tsrc.Repo, remote: tsrc.Remote) -> None:
full_path = self.workspace_path / repo.src
# fmt: off
ui.info_2(repo.src + ":", "Update remote", ui.reset,
ui.bold, remote.name, ui.reset,
"to new url:", ui.bold, remote.url)
# fmt: on
tsrc.git.run(full_path, "remote", "set-url", remote.name, remote.url)
def _reset_manifest_clone(self, url: str, *, branch: str) -> None:
tsrc.git.run(self.clone_path, "remote", "set-url", "origin", url)
tsrc.git.run(self.clone_path, "fetch")
tsrc.git.run(self.clone_path, "checkout", "-B", branch)
# fmt: off
tsrc.git.run(
self.clone_path, "branch", branch,
"--set-upstream-to", "origin/%s" % branch
)
# fmt: on
ref = "origin/%s" % branch
tsrc.git.run(self.clone_path, "reset", "--hard", ref)