Skip to content

Commit a226f18

Browse files
committed
cleanup; remove checkout during test
1 parent 4bd2185 commit a226f18

File tree

4 files changed

+31
-14
lines changed

4 files changed

+31
-14
lines changed

commit0/harness/constants.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class Files(TypedDict):
1515
eval_script: Dict[str, Path]
1616
patch: Dict[str, Path]
1717

18+
BASE_BRANCH = "commit0"
1819

1920
# Constants - Evaluation Log Directories
2021
BASE_IMAGE_BUILD_DIR = Path("logs/build_images/base")

commit0/harness/run_pytest_ids.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,24 @@ def main(
8585
if branch == "reference":
8686
commit_id = example["reference_commit"]
8787
else:
88-
try:
89-
local_repo.git.checkout(branch)
90-
local_branch = local_repo.branches[branch]
91-
commit_id = local_branch.commit.hexsha
92-
except Exception as e:
93-
raise Exception(f"Problem checking out branch {branch}.\n{e}")
88+
# Check if it's a local branch
89+
if branch in local_repo.branches:
90+
commit_id = local_repo.commit(branch)
91+
else:
92+
found_remote_branch = False
93+
for remote in local_repo.remotes:
94+
remote.fetch() # Fetch latest updates from each remote
95+
96+
# Check if the branch exists in this remote
97+
for ref in remote.refs:
98+
if ref.remote_head == branch: # Compare branch name without remote prefix
99+
commit_id = local_repo.commit(ref.name)
100+
found_remote_branch = True
101+
break # Branch found, no need to keep checking this remote
102+
if found_remote_branch:
103+
break # Stop checking other remotes if branch is found
104+
if not found_remote_branch:
105+
raise Exception(f"Branch {branch} does not exist locally or remotely.")
94106
patch = generate_patch_between_commits(
95107
local_repo, example["base_commit"], commit_id
96108
)

commit0/harness/setup.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from commit0.harness.utils import (
88
clone_repo,
99
)
10-
from commit0.harness.constants import RepoInstance, SPLIT
10+
from commit0.harness.constants import BASE_BRANCH, RepoInstance, SPLIT
1111

1212

1313
logging.basicConfig(
@@ -29,7 +29,12 @@ def main(
2929
continue
3030
clone_url = f"https://github.com/{example['repo']}.git"
3131
clone_dir = os.path.abspath(os.path.join(base_dir, repo_name))
32-
clone_repo(clone_url, clone_dir, example["base_commit"], logger)
32+
branch = dataset_name.split('/')[-1]
33+
repo = clone_repo(clone_url, clone_dir, branch, logger)
34+
if BASE_BRANCH in repo.branches:
35+
repo.git.branch('-d', BASE_BRANCH)
36+
repo.git.checkout('-b', BASE_BRANCH)
37+
logger.info("Checked out the base commit: commit 0")
3338

3439

3540
__all__ = []

commit0/harness/utils.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def extract_test_output(ss: str, pattern: str) -> str:
8585

8686

8787
def clone_repo(
88-
clone_url: str, clone_dir: str, commit: str, logger: logging.Logger
88+
clone_url: str, clone_dir: str, branch: str, logger: logging.Logger
8989
) -> git.Repo:
9090
"""Clone repo into the specified directory if it does not already exist.
9191
@@ -98,8 +98,8 @@ def clone_repo(
9898
URL of the repository to clone.
9999
clone_dir : str
100100
Directory where the repository will be cloned.
101-
commit : str
102-
The commit hash or branch/tag name to checkout.
101+
branch : str
102+
The branch/tag name to checkout.
103103
logger : logging.Logger
104104
The logger object.
105105
@@ -129,11 +129,10 @@ def clone_repo(
129129
except git.exc.GitCommandError as e:
130130
raise RuntimeError(f"Failed to clone repository: {e}")
131131

132-
logger.info(f"Checking out {commit}")
133132
try:
134-
repo.git.checkout(commit)
133+
repo.git.checkout(branch)
135134
except git.exc.GitCommandError as e:
136-
raise RuntimeError(f"Failed to check out {commit}: {e}")
135+
raise RuntimeError(f"Failed to check out {branch}: {e}")
137136

138137
return repo
139138

0 commit comments

Comments
 (0)