mirror of
https://github.com/Sea-Haven-Industries/open-swe.git
synced 2026-10-04 16:02:13 +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
|
// Don't log the full command with token for security reasons
|
||||||
repoPath: `${targetRepository.owner}/${targetRepository.repo}`,
|
repoPath: `${targetRepository.owner}/${targetRepository.repo}`,
|
||||||
branch: branchName,
|
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) {
|
} catch (e) {
|
||||||
const errorFields = getSandboxErrorFields(e);
|
const errorFields = getSandboxErrorFields(e);
|
||||||
logger.error("Failed to clone repository", errorFields ?? e);
|
logger.error("Failed to clone repository", errorFields ?? e);
|
||||||
|
|
|
||||||
|
|
@ -111,6 +111,7 @@ export type TargetRepository = {
|
||||||
owner: string;
|
owner: string;
|
||||||
repo: string;
|
repo: string;
|
||||||
branch?: string;
|
branch?: string;
|
||||||
|
baseCommit?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const GraphAnnotation = MessagesZodState.extend({
|
export const GraphAnnotation = MessagesZodState.extend({
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue