Example #1
0
    def check_branch(self, repo: Repo) -> Tuple[Optional[Error], str]:
        """Check that the current branch:
            * exists
            * matches the one in the manifest

        * Raise Error if the branch does not exist (because we can't
          do anything else in that case)

        * _Return_ on Error if the current branch does not match the
          one in the manifest - because we still want to run
          `git merge @upstream` in that case

        * Otherwise, return the current branch
        """
        repo_path = self.workspace_path / repo.dest
        current_branch = None
        try:
            current_branch = get_current_branch(repo_path)
        except Error:
            raise Error("Not on any branch")

        if current_branch and current_branch != repo.branch:
            return (
                IncorrectBranch(actual=current_branch, expected=repo.branch),
                current_branch,
            )
        else:
            return None, current_branch
Example #2
0
def test_repo_default_branch_not_master(tsrc_cli: CLI, git_server: GitServer,
                                        workspace_path: Path) -> None:
    git_server.add_repo("foo", default_branch="devel")

    tsrc_cli.run("init", git_server.manifest_url)

    foo_path = workspace_path / "foo"
    assert get_current_branch(foo_path) == "devel"
Example #3
0
def test_can_set_remote_head(tmp_path: Path, git_server: GitServer) -> None:
    git_server.add_repo("foo")
    git_server.manifest.change_branch("main")
    git_server.manifest.set_head("main")

    run_git(tmp_path, "clone", git_server.manifest_url, "manifest")

    assert get_current_branch(tmp_path / "manifest") == "main"
Example #4
0
def test_default_branch_devel(workspace_path: Path, git_server: GitServer) -> None:
    foo_url = git_server.add_repo("foo", default_branch="devel")
    run_git(workspace_path, "clone", foo_url)
    foo_path = workspace_path / "foo"
    cloned_branch = get_current_branch(foo_path)
    assert cloned_branch == "devel"

    manifest = read_remote_manifest(workspace_path, git_server)
    foo_config = manifest.get_repo("foo")
    assert foo_config.branch == "devel"
Example #5
0
def test_init_manifest_head_is_main(tsrc_cli: CLI, git_server: GitServer,
                                    workspace_path: Path) -> None:
    git_server.add_repo("foo")
    git_server.manifest.change_branch("main")
    git_server.manifest.set_head("main")
    manifest_url = git_server.manifest_url
    tsrc_cli.run("init", manifest_url)

    manifest_clone = workspace_path / ".tsrc/manifest"
    manifest_branch = get_current_branch(manifest_clone)
    assert manifest_branch == "main"
Example #6
0
def test_init_manifest_head_is_master(tsrc_cli: CLI, git_server: GitServer,
                                      workspace_path: Path) -> None:
    git_server.add_repo("foo")
    git_server.add_repo("bar")
    manifest_url = git_server.manifest_url
    tsrc_cli.run("init", manifest_url)

    assert_cloned(workspace_path, "foo")
    assert_cloned(workspace_path, "bar")
    manifest_clone = workspace_path / ".tsrc/manifest"
    manifest_branch = get_current_branch(manifest_clone)
    assert manifest_branch == "master"
Example #7
0
def test_uses_correct_branch_for_repo(tsrc_cli: CLI, git_server: GitServer,
                                      workspace_path: Path) -> None:
    """Scenario:
    * Create a foo repo with two branches `master` and `next`
    * Set the branch to `next` in the manifest
    * Init the repository
    * Check that the cloned project is on the `next` branch

    """
    git_server.add_repo("foo")
    git_server.push_file("foo", "next.txt", branch="next")
    git_server.manifest.set_repo_branch("foo", "next")

    manifest_url = git_server.manifest_url
    tsrc_cli.run("init", manifest_url)

    foo_path = workspace_path / "foo"
    assert get_current_branch(foo_path) == "next"
Example #8
0
 def current_branch(self) -> str:
     return get_current_branch(self.clone_path)