Coverage for src / competitive_verifier / git.py: 100%

18 statements  

« prev     ^ index     » next       coverage.py v7.13.1, created at 2026-03-05 16:00 +0000

1import datetime 

2import pathlib 

3from collections.abc import Iterable 

4from typing import TYPE_CHECKING 

5 

6from .exec import command_stdout 

7 

8if TYPE_CHECKING: 

9 from _typeshed import StrPath 

10 

11 

12def get_commit_time(files: Iterable[pathlib.Path]) -> datetime.datetime: 

13 code = ["git", "log", "-1", "--date=iso", "--pretty=%ad", "--", *map(str, files)] 

14 stdout = command_stdout(code) 

15 timestamp = stdout.strip() 

16 if not timestamp: 

17 return datetime.datetime.min.replace(tzinfo=datetime.timezone.utc) 

18 return datetime.datetime.strptime(timestamp, "%Y-%m-%d %H:%M:%S %z") 

19 

20 

21def ls_files(*args: "StrPath") -> set[pathlib.Path]: 

22 stdout = command_stdout(["git", "ls-files", "-z", *[str(p) for p in (args or [])]]) 

23 return set(map(pathlib.Path, filter(None, stdout.split("\0")))) 

24 

25 

26def get_root_directory() -> pathlib.Path: 

27 stdout = command_stdout(["git", "rev-parse", "--show-toplevel"]) 

28 return pathlib.Path(stdout.strip())