Skip to content

Commit

Permalink
Merge pull request #89 from Nikita-Barabanov/main
Browse files Browse the repository at this point in the history
Change checkout to show in deliver git
  • Loading branch information
FrBrGeorge authored Oct 24, 2023
2 parents 3d15816 + 71f801d commit 307018f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
11 changes: 5 additions & 6 deletions hworker/deliver/git/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def update_all() -> None:
pull(repo)


def get_homework_content(repo: git.Repo, root: Path) -> dict:
def get_homework_content(repo: git.Repo, root: Path, commit: str) -> dict:
"""Extracts tests, solution and URLS from homework and pack into dict
:param root: local path to homework
Expand All @@ -78,9 +78,10 @@ def get_homework_content(repo: git.Repo, root: Path) -> dict:
get_logger(__name__).debug(f"Getting {root} content")
content = {
path.relative_to(root).as_posix(): FileObject(
content=path.read_bytes(), timestamp=float(repo.git.log("-1", "--format=%ct", "--date=default", "--", path))
content=repo.git.show("--no-patch", commit, path),
timestamp=float(repo.git.log("-1", "--format=%ct", "--date=default", "--", commit, path)),
)
for path in root.rglob("*")
for path in map(lambda p: Path(root, p), repo.git.ls_tree(commit, root, r=True, name_only=True).split("\n"))
if path.is_file() and f"{os.sep}." not in str(path.relative_to(root.parent))
}
return content
Expand Down Expand Up @@ -112,12 +113,10 @@ def download_all() -> None:
get_logger(__name__).warning(f"Got empty repo from {student_id} student!")
continue
for task in get_tasks_list():
repo.git.checkout(repo.heads[0])
if os.path.isdir((task_path := Path(local_path(student_id), get_task_info(task).get("deliver_ID", "")))):
commits = [_ for _ in get_commits(repo, task_path) if _]
for commit in commits:
repo.git.checkout(commit[0])
content = get_homework_content(repo, task_path)
content = get_homework_content(repo, task_path, commit[0])
store(
Homework(
content=content,
Expand Down
2 changes: 1 addition & 1 deletion tests/test_deliver.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def example_git_repo(tmp_path_factory):
(test_path / config.get_remote_name()).write_bytes(b"UserN:TaskN\n")
repo.git.add(".")
repo.git.commit(message="test commit")
return repo, repo_path
return repo, repo_path, repo.git.log("-n", "1", "--pretty=format:%H")


class TestDeliverGit:
Expand Down

0 comments on commit 307018f

Please sign in to comment.