1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
"""Tests for project label and commit log helpers."""
from __future__ import annotations
from pathlib import Path
import pygit2
from pygit2 import Signature
from pygittools.tui.log_list import CommitLogList
from pygittools.tui.project_label import repo_project_label
SIG = Signature("t", "t@example.com", 0)
def test_repo_project_label_falls_back_to_worktree(tmp_path: Path) -> None:
repo_dir = tmp_path / "standalone"
repo_dir.mkdir()
pygit2.init_repository(str(repo_dir), bare=False)
assert repo_project_label(repo_dir) == str(repo_dir.resolve())
def test_repo_project_label_uses_worktree_for_git_dir(tmp_path: Path) -> None:
repo_dir = tmp_path / "pygitweb"
repo_dir.mkdir()
repo = pygit2.init_repository(str(repo_dir), bare=False)
assert repo_project_label(Path(repo.path)) == str(repo_dir.resolve())
def test_commit_log_list_loads_head_commit(tmp_path: Path) -> None:
repo = pygit2.init_repository(str(tmp_path / "repo"), bare=False)
tree = repo.index.write_tree()
repo.create_commit("HEAD", SIG, SIG, "feat: first", tree, [])
log = CommitLogList()
log.refresh(repo)
assert str(repo.head.target)[:7] in log.status_hint()