Skip to content

Commit feb0a71

Browse files
committed
feat: add command timeout handling, add ensure_git_author_identity
1 parent 4f0ae69 commit feb0a71

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

grading_lib/common.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,10 @@ def run_executable(
9494
return CommandResult(True, " ".join(args), make_cmd_output.decode())
9595
except subprocess.CalledProcessError as e:
9696
return CommandResult(False, " ".join(args), e.output.decode())
97-
except subprocess.TimeoutExpired as e:
98-
return CommandResult(False, " ".join(args), e.output.decode())
97+
except subprocess.TimeoutExpired:
98+
return CommandResult(
99+
False, " ".join(args), f"Command timed out after {timeout} seconds."
100+
)
99101

100102

101103
def ensure_lf_line_ending(path: Path | str) -> CommandResult:

grading_lib/repository.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,32 @@
55
import uuid
66
from pathlib import Path
77

8-
from git import Head, Repo
9-
from git.refs.tag import Tag
8+
from git import Head, Repo, Tag
109
from git.repo.fun import is_git_dir
1110

1211
from .common import BaseTestCase, CommandResult, run_executable
1312

1413

14+
def ensure_git_author_identity(
15+
name="ou-cs3560-grading-script", email="[email protected]"
16+
):
17+
"""
18+
Set user.name and user.email is not set unless they are already set.
19+
"""
20+
existing_user_name = subprocess.run(
21+
"git config --get user.name", shell=True, capture_output=True
22+
)
23+
existing_user_email = subprocess.run(
24+
"git config --get user.email", shell=True, capture_output=True
25+
)
26+
27+
if existing_user_name is not None or len(existing_user_name.strip()) == 0:
28+
subprocess.run(["git", "config", "--global", "user.name", name])
29+
30+
if existing_user_email is not None or len(existing_user_email.strip()) == 0:
31+
subprocess.run(["git", "config", "--global", "user.email", email])
32+
33+
1534
class Repository:
1635
"""
1736
A wrapper over git.Repo with our own utilities.

0 commit comments

Comments
 (0)