def test_singular_remote(tsrc_cli: CLI, git_server: GitServer, workspace_path: Path) -> None: """ Scenario: * Create a manifest that contains one repo with two remotes ('origin' and 'vpn') * Make sure that the `origin` URL is valid but the `vpn` URL is not. * Run `tsrc init --singular-remote origin` * Check that foo only has one remote called 'origin' """ foo_url = git_server.add_repo("foo") vpn_url = "/does/not/exist" # fmt: off git_server.manifest.set_repo_remotes("foo", [("origin", foo_url), ("vpn", vpn_url)]) # fmt: on # only use "origin" remote tsrc_cli.run("init", git_server.manifest_url, "-r", "origin") foo_path = workspace_path / "foo" _, output = run_git_captured(foo_path, "remote", "show", check=True) assert output == "origin"
def update_submodules(self, repo: Repo) -> str: repo_path = self.workspace_path / repo.dest cmd = ("submodule", "update", "--init", "--recursive") if self.parallel: _, out = run_git_captured(repo_path, *cmd, check=True) return out else: self.run_git(repo_path, *cmd) return ""
def test_add_repo_updates_manifest(workspace_path: Path, git_server: GitServer) -> None: git_server.add_repo("foo/bar") git_server.add_repo("spam/eggs") manifest = read_remote_manifest(workspace_path, git_server) repos = manifest.get_repos() assert len(repos) == 2 for repo in repos: clone_url = repo.clone_url _, out = run_git_captured(workspace_path, "ls-remote", clone_url) assert "refs/heads/master" in out
def process(self, index: int, count: int, repo: Repo) -> Outcome: # We just need to compute a summary here with the log between # self.from_ref and self.to_ref # # Note: make sure that when there is no diff between # self.from_ref and self.to_ref, the summary is empty, # so that the repo is not shown by OutcomeCollection.print_summary() repo_path = self.workspace_path / repo.dest if not repo_path.exists(): raise MissingRepo(repo.dest) # The main reason for the `git log` command to fail is if `self.from_ref` or # `self.to_ref` references are not found for the repo, so check for this case # explicitly rc, _ = run_git_captured(repo_path, "rev-parse", self.from_ref, check=False) if rc != 0: raise Error(f"{self.from_ref} not found") rc, _ = run_git_captured(repo_path, "rev-parse", self.to_ref, check=False) if rc != 0: raise Error(f"{self.to_ref} not found") colors = ["green", "reset", "yellow", "reset", "bold blue", "reset"] log_format = "%m {}%h{} - {}%d{} %s {}<%an>{}" log_format = log_format.format(*("%C({})".format(x) for x in colors)) cmd = [ "log", "--color=always", f"--pretty=format:{log_format}", f"{self.from_ref}...{self.to_ref}", ] rc, out = run_git_captured(repo_path, *cmd, check=True) if out: lines = [repo.dest, "-" * len(repo.dest), out] return Outcome.from_lines(lines) else: return Outcome.empty()
def get_remote(self, repo: Repo, name: str) -> Optional[Remote]: full_path = self.workspace_path / repo.dest rc, url = run_git_captured(full_path, "remote", "get-url", name, check=False) if rc != 0: return None else: return Remote(name=name, url=url)
def test_resets_to_tag(tsrc_cli: CLI, git_server: GitServer, workspace_path: Path) -> None: """Scenario: * Create a repository containing a v1.0 tag * Add a commit on top of the v1.0 tag * Configure the manifest to specify that the repo should be reset at the v1.0 tag * Run `tsrc init` * Check the repo was cloned at the correct revision """ git_server.add_repo("foo") git_server.tag("foo", "v1.0") git_server.push_file("foo", "2.txt", message="Working on v2") git_server.manifest.set_repo_tag("foo", "v1.0") manifest_url = git_server.manifest_url tsrc_cli.run("init", manifest_url) foo_path = workspace_path / "foo" _, expected_ref = run_git_captured(foo_path, "rev-parse", "v1.0") _, actual_ref = run_git_captured(foo_path, "rev-parse", "HEAD") assert expected_ref == actual_ref
def test_resets_to_sha1(tsrc_cli: CLI, git_server: GitServer, workspace_path: Path) -> None: git_server.add_repo("foo") initial_sha1 = git_server.get_sha1("foo") git_server.manifest.set_repo_sha1("foo", initial_sha1) git_server.push_file("foo", "2.txt", message="Working on v2") manifest_url = git_server.manifest_url tsrc_cli.run("init", manifest_url) foo_path = workspace_path / "foo" _, actual_ref = run_git_captured(foo_path, "rev-parse", "HEAD") assert initial_sha1 == actual_ref
def sync_repo_to_branch(self, repo: Repo, *, current_branch: str) -> str: repo_path = self.workspace_path / repo.dest if self.parallel: # Note: we want the summary to: # * be empty if the repo was already up-to-date # * contain the diffstat if the merge with upstream succeeds rc, out = run_git_captured( repo_path, "log", "--oneline", "HEAD..@{upstream}", check=False ) if rc == 0 and not out: return "" _, merge_output = run_git_captured( repo_path, "merge", "--ff-only", "@{upstream}", check=True ) return merge_output else: # Note: no summary here, because the output of `git merge` # is not captured, so the diffstat or the "Already up to # date" message are directly shown to the user try: self.run_git(repo_path, "merge", "--ff-only", "@{upstream}") except Error: raise Error("updating branch failed") return ""
def test_several_remotes(tsrc_cli: CLI, git_server: GitServer, workspace_path: Path) -> None: foo_url = git_server.add_repo("foo") # fmt: off git_server.manifest.set_repo_remotes("foo", [("origin", foo_url), ("upstream", "*****@*****.**")]) # fmt: on tsrc_cli.run("init", git_server.manifest_url) foo_path = workspace_path / "foo" rc, output = run_git_captured(foo_path, "remote", "get-url", "upstream", check=False) assert rc == 0, output assert output == "*****@*****.**"
def test_tag(workspace_path: Path, git_server: GitServer) -> None: foo_url = git_server.add_repo("foo") git_server.tag("foo", "v0.1", branch="master") _, out = run_git_captured(workspace_path, "ls-remote", foo_url) assert "refs/tags/v0.1" in out