Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def add_remote(self, repo: tsrc.Repo, remote: tsrc.Remote) -> None:
full_path = self.workspace_path / repo.src
# fmt: off
ui.info_2(repo.src + ":", "Add remote",
ui.bold, remote.name, ui.reset,
ui.brown, "(%s)" % remote.url)
# fmt: on
tsrc.git.run(full_path, "remote", "add", 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)
def push(self) -> None:
ui.info_2("Running git push")
remote_name = self.remote_name or "origin"
if self.args.push_spec:
push_spec = self.args.push_spec
else:
push_spec = "%s:%s" % (self.current_branch, self.remote_branch)
cmd = ["push", "-u", remote_name, push_spec]
if self.args.force:
cmd.append("--force")
tsrc.git.run(self.repo_path, *cmd)
def sync_repo_to_branch(repo_path: Path) -> None:
ui.info_2("Updating branch")
try:
tsrc.git.run(repo_path, "merge", "--ff-only", "@{upstream}")
except tsrc.Error:
raise tsrc.Error("updating branch failed")
def read(cls, working_path: Path, *, workspace: tsrc.Workspace) -> "RepositoryInfo":
repo_path = tsrc.git.get_repo_root(working_path=working_path)
current_branch = tsrc.git.get_current_branch(repo_path)
tracking_ref = tsrc.git.get_tracking_ref(repo_path)
# TODO: we should know the name of the remote at this point,
# no need to hard-code 'origin'!
rc, out = tsrc.git.run_captured(
repo_path, "remote", "get-url", "origin", check=False
)
if rc == 0:
url = out
if not url:
raise NoRemoteConfigured(repo_path, "origin")
project_name = project_name_from_url(url)
service = service_from_url(url=url, workspace=workspace)