mirror of
https://github.com/Sea-Haven-Industries/open-swe.git
synced 2026-09-30 09:13:14 +00:00
feat: add baseCommit support for repository initialization (#101)
* Apply patch * Apply patch * format * small logic changes --------- Co-authored-by: Brace Sproul <46789226+bracesproul@users.noreply.github.com> Co-authored-by: bracesproul <braceasproul@gmail.com>
This commit is contained in:
parent
1c12f6f754
commit
41cdd8debe
2 changed files with 48 additions and 1 deletions
|
|
@ -596,8 +596,54 @@ export async function cloneRepo(
|
|||
// Don't log the full command with token for security reasons
|
||||
repoPath: `${targetRepository.owner}/${targetRepository.repo}`,
|
||||
branch: branchName,
|
||||
baseCommit: targetRepository.baseCommit,
|
||||
});
|
||||
return await sandbox.process.executeCommand(gitCloneCommand.join(" "));
|
||||
|
||||
const cloneResult = await sandbox.process.executeCommand(
|
||||
gitCloneCommand.join(" "),
|
||||
);
|
||||
|
||||
if (!targetRepository.baseCommit) {
|
||||
if (cloneResult.exitCode !== 0) {
|
||||
logger.error("Failed to clone repository", {
|
||||
targetRepository,
|
||||
cloneResult,
|
||||
});
|
||||
throw new Error("Failed to clone repository");
|
||||
}
|
||||
return cloneResult;
|
||||
}
|
||||
|
||||
// If a baseCommit is specified, checkout that commit after cloning
|
||||
const absoluteRepoDir = getRepoAbsolutePath(targetRepository);
|
||||
|
||||
logger.info("Checking out base commit", {
|
||||
baseCommit: targetRepository.baseCommit,
|
||||
repoPath: `${targetRepository.owner}/${targetRepository.repo}`,
|
||||
});
|
||||
|
||||
const checkoutResult = await sandbox.process.executeCommand(
|
||||
`git checkout ${targetRepository.baseCommit}`,
|
||||
absoluteRepoDir,
|
||||
undefined,
|
||||
TIMEOUT_SEC,
|
||||
);
|
||||
|
||||
if (checkoutResult.exitCode !== 0) {
|
||||
logger.error("Failed to checkout base commit", {
|
||||
baseCommit: targetRepository.baseCommit,
|
||||
checkoutResult,
|
||||
});
|
||||
throw new Error(
|
||||
`Failed to checkout base commit ${targetRepository.baseCommit}: ${checkoutResult.result}`,
|
||||
);
|
||||
}
|
||||
|
||||
logger.info("Successfully checked out base commit", {
|
||||
baseCommit: targetRepository.baseCommit,
|
||||
});
|
||||
|
||||
return cloneResult;
|
||||
} catch (e) {
|
||||
const errorFields = getSandboxErrorFields(e);
|
||||
logger.error("Failed to clone repository", errorFields ?? e);
|
||||
|
|
|
|||
|
|
@ -111,6 +111,7 @@ export type TargetRepository = {
|
|||
owner: string;
|
||||
repo: string;
|
||||
branch?: string;
|
||||
baseCommit?: string;
|
||||
};
|
||||
|
||||
export const GraphAnnotation = MessagesZodState.extend({
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue