Skip to content

Commit

Permalink
fix: Remove nested git repositories before adding files in SWE-bench (#…
Browse files Browse the repository at this point in the history
…6536)

Co-authored-by: Xingyao Wang <[email protected]>
  • Loading branch information
magic3007 and xingyaoww authored Feb 28, 2025
1 parent 996757f commit 8a58e72
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions evaluation/benchmarks/swe_bench/run_infer.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,32 @@ def complete_runtime(
f'Failed to git config --global core.pager "": {str(obs)}',
)

# First check for any git repositories in subdirectories
action = CmdRunAction(command='find . -type d -name .git -not -path "./.git"')
action.set_hard_timeout(600)
logger.info(action, extra={'msg_type': 'ACTION'})
obs = runtime.run_action(action)
logger.info(obs, extra={'msg_type': 'OBSERVATION'})
assert_and_raise(
isinstance(obs, CmdOutputObservation) and obs.exit_code == 0,
f'Failed to find git repositories: {str(obs)}',
)

git_dirs = [p for p in obs.content.strip().split('\n') if p]
if git_dirs:
# Remove all .git directories in subdirectories
for git_dir in git_dirs:
action = CmdRunAction(command=f'rm -rf "{git_dir}"')
action.set_hard_timeout(600)
logger.info(action, extra={'msg_type': 'ACTION'})
obs = runtime.run_action(action)
logger.info(obs, extra={'msg_type': 'OBSERVATION'})
assert_and_raise(
isinstance(obs, CmdOutputObservation) and obs.exit_code == 0,
f'Failed to remove git directory {git_dir}: {str(obs)}',
)

# add all files
action = CmdRunAction(command='git add -A')
action.set_hard_timeout(600)
logger.info(action, extra={'msg_type': 'ACTION'})
Expand Down

0 comments on commit 8a58e72

Please sign in to comment.