def test_ahead_1_commit(self) -> None: status = GitStatus(self.dummy_path) status.branch = "master" status.ahead = 1 # fmt: off assert status.describe() == [ ui.green, "master", ui.reset, ui.blue, f"{UP}1 commit", ui.reset ]
def get_env_for_repo(self, repo: Repo) -> Dict[str, str]: workspace_vars = get_workspace_vars(self.workspace) repo_vars = get_repo_vars(repo) repo_path = self.workspace.root_path / repo.dest status = GitStatus(repo_path) status.update() status_vars = get_status_vars(status) res = {} res.update(repo_vars) res.update(status_vars) res.update(workspace_vars) return res
def test_diverged(self) -> None: status = GitStatus(self.dummy_path) status.branch = "master" status.ahead = 1 status.behind = 2 # fmt: off assert status.describe() == [ ui.green, "master", ui.reset, ui.blue, f"{UP}1 commit", ui.reset, ui.blue, f"{DOWN}2 commits", ui.reset, ]
def get_status(self) -> GitStatus: status = GitStatus(self.path) status.update() return status
def test_on_tag(self) -> None: status = GitStatus(self.dummy_path) status.tag = "v0.1" assert status.describe() == [ui.yellow, "on", "v0.1", ui.reset]
def test_on_sha1(self) -> None: status = GitStatus(self.dummy_path) status.sha1 = "b6cfd80" assert status.describe() == [ui.red, "b6cfd80", ui.reset]
def test_up_to_date(self) -> None: status = GitStatus(self.dummy_path) status.branch = "master" assert status.describe() == [ui.green, "master", ui.reset]
def test_git_status_vars(tmp_path: Path) -> None: git_status = GitStatus(tmp_path) git_status.untracked = 0 git_status.added = 1 git_status.staged = 2 git_status.not_staged = 3 git_status.behind = 4 git_status.ahead = 5 git_status.branch = "other" git_status.sha1 = "abcde43" git_status.tag = "some-tag" git_status.dirty = True actual = get_status_vars(git_status) assert actual["TSRC_PROJECT_STATUS_UNTRACKED"] == "0" assert actual["TSRC_PROJECT_STATUS_ADDED"] == "1" assert actual["TSRC_PROJECT_STATUS_STAGED"] == "2" assert actual["TSRC_PROJECT_STATUS_NOT_STAGED"] == "3" assert actual["TSRC_PROJECT_STATUS_BEHIND"] == "4" assert actual["TSRC_PROJECT_STATUS_AHEAD"] == "5" assert actual["TSRC_PROJECT_STATUS_BRANCH"] == "other" assert actual["TSRC_PROJECT_STATUS_SHA1"] == "abcde43" assert actual["TSRC_PROJECT_STATUS_TAG"] == "some-tag" assert actual["TSRC_PROJECT_STATUS_DIRTY"] == "true"