Skip to content

Commit 7612a56

Browse files
magic3007xingyaoww
authored andcommitted
fix: Remove nested git repositories before adding files in SWE-bench (All-Hands-AI#6536)
Co-authored-by: Xingyao Wang <[email protected]>
1 parent 9db439f commit 7612a56

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

evaluation/benchmarks/swe_bench/run_infer.py

+26
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,32 @@ def complete_runtime(
371371
f'Failed to git config --global core.pager "": {str(obs)}',
372372
)
373373

374+
# First check for any git repositories in subdirectories
375+
action = CmdRunAction(command='find . -type d -name .git -not -path "./.git"')
376+
action.set_hard_timeout(600)
377+
logger.info(action, extra={'msg_type': 'ACTION'})
378+
obs = runtime.run_action(action)
379+
logger.info(obs, extra={'msg_type': 'OBSERVATION'})
380+
assert_and_raise(
381+
isinstance(obs, CmdOutputObservation) and obs.exit_code == 0,
382+
f'Failed to find git repositories: {str(obs)}',
383+
)
384+
385+
git_dirs = [p for p in obs.content.strip().split('\n') if p]
386+
if git_dirs:
387+
# Remove all .git directories in subdirectories
388+
for git_dir in git_dirs:
389+
action = CmdRunAction(command=f'rm -rf "{git_dir}"')
390+
action.set_hard_timeout(600)
391+
logger.info(action, extra={'msg_type': 'ACTION'})
392+
obs = runtime.run_action(action)
393+
logger.info(obs, extra={'msg_type': 'OBSERVATION'})
394+
assert_and_raise(
395+
isinstance(obs, CmdOutputObservation) and obs.exit_code == 0,
396+
f'Failed to remove git directory {git_dir}: {str(obs)}',
397+
)
398+
399+
# add all files
374400
action = CmdRunAction(command='git add -A')
375401
action.set_hard_timeout(600)
376402
logger.info(action, extra={'msg_type': 'ACTION'})

0 commit comments

Comments
 (0)