Skip to content

Commit

Permalink
Undo commit after failed push #171
Browse files Browse the repository at this point in the history
  • Loading branch information
meffmadd committed Dec 20, 2023
1 parent 80ec36c commit 227005d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -303,14 +303,8 @@ async def put(self, lecture_id: int, assignment_id: int, repo: str):
self.log.error(e.response)
raise HTTPError(e.code, reason=e.response.reason)

# TODO: similar logic for push instruction submission
# however we cannot push to edit repository when no submission exists
# reverse order:
# first create submission (with fake commit hash since autograder does not need any commit hash if submission is set to edited),
# then set submission to edited and update username to student username -> need to be able to set this later (in PUT?) -> also refactor SubmissionEditHandler? -> create new endpoint?
# then push to edit repository directly (not using SubmissionEditHandler),

# differentiate between "normal" edit and "create" edit by sub_id -> if it is None we know we are in submission creation mode instead of edit mode
# differentiate between "normal" edit and "create" edit by sub_id -> if it is None we know we are in
# submission creation mode instead of edit mode
if repo == "edit" and sub_id is None:
submission = Submission(commit_hash="0" * 40)
response: dict = await self.request_service.request(
Expand Down Expand Up @@ -443,6 +437,7 @@ async def put(self, lecture_id: int, assignment_id: int, repo: str):
git_service.push(f"grader_{repo}", force=True)
except GitError as e:
self.log.error("GitError:\n" + e.error)
git_service.undo_commit()
raise HTTPError(HTTPStatus.INTERNAL_SERVER_ERROR, reason=str(e.error))

if submit and repo == "assignment":
Expand Down
6 changes: 6 additions & 0 deletions grader_labextension/grader_labextension/services/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,12 @@ def go_to_commit(self, commit_hash):
self.log.info(f"Show commit with hash {commit_hash}")
self._run_command(f"git checkout {commit_hash}", cwd=self.path)

def undo_commit(self, n: int = 1) -> None:
self.log.info(f"Undoing {n} commit(s)")
self._run_command(f"git reset --hard HEAD~{n}", cwd=self.path)
self._run_command(f"git gc", cwd=self.path)


def pull(self, origin: str, branch="main", force=False):
"""Pulls a repository
Expand Down

0 comments on commit 227005d

Please sign in to comment.