open-swe icon indicating copy to clipboard operation
open-swe copied to clipboard

Support empty repositories

Open bracesproul opened this issue 4 months ago • 1 comments

We should update the initialize sandbox node to support initializing the sandbox for empty repos. If cloing the repo fails, and the error message includes the string: remote repository is empty, instead of failing, it should run a new flow for setting up the sandbox:

  • create a new directory where the repo would've been cloned to, with the name of the dir matching the repo name
  • inside that dir, run the git commands to initialize the repo git init, git remote add origin <git url>, git branch -M main
  • then, create a .gitignore file in the root of the repo, and write the default gitignore contents (find this string here: apps/open-swe/src/utils/default-gitignore.ts - it includes a default gitignore for both node.js and python repos)
  • finally, commit and push these changes. then you can continue to the main execution

If we don't do this, the git SDK we use will fail if you try to clone an empty repository

Agent Context { "tasks": [ { "id": "49342c69-21c6-4687-93ae-64fffa3f271c", "taskIndex": 0, "request": "[original issue]\n**Support empty repositories**\nWe should update the initialize sandbox node to support initializing the sandbox for empty repos. If cloing the repo fails, and the error message includes the string: `remote repository is empty`, instead of failing, it should run a new flow for setting up the sandbox:\n\n- create a new directory where the repo would've been cloned to, with the name of the dir matching the repo name\n- inside that dir, run the git commands to initialize the repo `git init`, `git remote add origin `, `git branch -M main`\n- then, create a `.gitignore` file in the root of the repo, and write the default gitignore contents (find this string here: `apps/open-swe/src/utils/default-gitignore.ts` - it includes a default gitignore for both node.js and python repos)\n- finally, commit and push these changes. then you can continue to the main execution\n\nIf we don't do this, the git SDK we use will fail if you try to clone an empty repository", "title": "Add support for empty repositories in the initialize sandbox node", "createdAt": 1754504086224, "completed": true, "planRevisions": [ { "revisionIndex": 0, "plans": [ { "index": 0, "plan": "**Modify the initialize-sandbox.ts file to handle empty repository errors**\n\nIn `/home/daytona/open-swe/apps/open-swe/src/graphs/shared/initialize-sandbox.ts`:\n- Add imports for `DEFAULT_GITIGNORE` from `../../utils/default-gitignore.js` and `writeFile` from `../../utils/read-write.js`\n- After line 291, add a new conditional block to detect when `cloneRepoRes instanceof Error && cloneRepoRes.message.includes('remote repository is empty')`\n- When detected, implement the empty repository initialization flow:\n 1. Create the repository directory using `sandbox.process.executeCommand()` with `mkdir -p ${absoluteRepoDir}`\n 2. Initialize git repository by executing `git init` in the created directory\n 3. Add remote origin with `git remote add origin https://github.com/${targetRepository.owner}/${targetRepository.repo}.git`\n 4. Set main branch with `git branch -M main`\n 5. Create `.gitignore` file at `${absoluteRepoDir}/.gitignore` using `writeFile()` with content from `DEFAULT_GITIGNORE`\n 6. Stage the .gitignore file using `sandbox.git.add(absoluteRepoDir, ['.gitignore'])`\n 7. Commit changes using `sandbox.git.commit()` with bot user credentials from `process.env.GITHUB_APP_NAME`\n 8. Push to remote using `sandbox.git.push(absoluteRepoDir, 'git', githubInstallationToken)`\n 9. Set `newBranchName = 'main'` and emit success event for the clone action\n- Ensure proper error handling with try-catch blocks and appropriate error messages via `emitStepEvent()`\n- Continue with the normal execution flow after successful empty repo initialization", "completed": true, "summary": "Successfully implemented support for empty repositories in the initialize-sandbox.ts file.\n\n### Changes Made:\n1. **Added required imports** at the top of the file:\n - `DEFAULT_GITIGNORE` from `../../utils/default-gitignore.js`\n - `writeFile` from `../../utils/read-write.js`\n\n2. **Implemented empty repository detection and handling** (lines 294-443):\n - Detects when clone fails with \"remote repository is empty\" error message\n - Creates repository directory structure using `mkdir -p`\n - Initializes git repository with `git init`\n - Configures remote origin pointing to the GitHub repository\n - Sets main branch as the default branch\n - Creates .gitignore file with default Node.js and Python patterns\n - Stages, commits, and pushes the initial commit with proper bot credentials\n - Continues with normal sandbox initialization flow after successful setup\n\n3. **Added comprehensive error handling**:\n - Each step validates success and throws descriptive errors on failure\n - Uses existing `emitStepEvent()` mechanism for progress tracking\n - Logs all operations and errors using the existing logger\n\nThe implementation ensures that empty repositories are properly initialized with sensible defaults, allowing the sandbox to function correctly even when starting with an empty repository. This prevents the git SDK from failing when attempting to clone empty repositories." }, { "index": 1, "plan": "**Build the project and run linting/formatting**\n\nRun the following commands from the repository root:\n- `yarn build` to build all packages including the shared package and open-swe app\n- `yarn lint:fix` to fix any linting issues\n- `yarn format` to format the code according to project standards", "completed": true, "summary": "Successfully built the project and ran linting/formatting commands.\n\n### Commands Executed:\n1. **`yarn build`** - Built all packages successfully:\n - @open-swe/shared (cached)\n - @open-swe/cli \n - @open-swe/web (with some Edge Runtime warnings)\n - @open-swe/agent (cached)\n - Total build time: ~1m 23s\n\n2. **`yarn lint:fix`** - Ran ESLint with auto-fix:\n - Fixed formatting issues across all packages\n - Some warnings remain (React refresh, unused variables) but are non-blocking\n - All critical linting issues resolved\n\n3. **`yarn format`** - Ran Prettier formatting:\n - Checked 200+ files across all packages\n - All files already properly formatted (no changes needed)\n - Code style consistency maintained\n\nThe project now builds successfully with the new empty repository support feature properly integrated and all code quality checks passing." } ], "createdAt": 1754504086224, "createdBy": "agent" } ], "activeRevisionIndex": 0, "pullRequestNumber": 694, "completedAt": 1754504637925, "summary": "I've successfully implemented support for empty repositories in the initialize-sandbox node. The changes include detecting empty repository errors, creating the repository directory, initializing git, adding a default .gitignore, and pushing initial changes. The implementation ensures seamless handling of empty repositories while maintaining the existing code structure and error handling patterns." } ], "activeTaskIndex": 0 }

bracesproul avatar Aug 06 '25 18:08 bracesproul

🤖 Open SWE has been triggered for this issue. Processing...

View run in Open SWE here (this URL will only work for @bracesproul)

Dev Metadata { "runId": "1f072f04-6c79-6f73-b5bf-768347f363cc", "threadId": "6d6afb2b-e135-48b4-8dfd-95745179b8cb" }

🤖 Plan Generated

I've generated a plan for this issue and will proceed to implement it since auto-accept is enabled.

Plan: Add support for empty repositories in the initialize sandbox node

  • Task 1:
**Modify the initialize-sandbox.ts file to handle empty repository errors**

In `/home/daytona/open-swe/apps/open-swe/src/graphs/shared/initialize-sandbox.ts`:
- Add imports for `DEFAULT_GITIGNORE` from `../../utils/default-gitignore.js` and `writeFile` from `../../utils/read-write.js`
- After line 291, add a new conditional block to detect when `cloneRepoRes instanceof Error && cloneRepoRes.message.includes('remote repository is empty')`
- When detected, implement the empty repository initialization flow:
  1. Create the repository directory using `sandbox.process.executeCommand()` with `mkdir -p ${absoluteRepoDir}`
  2. Initialize git repository by executing `git init` in the created directory
  3. Add remote origin with `git remote add origin https://github.com/${targetRepository.owner}/${targetRepository.repo}.git`
  4. Set main branch with `git branch -M main`
  5. Create `.gitignore` file at `${absoluteRepoDir}/.gitignore` using `writeFile()` with content from `DEFAULT_GITIGNORE`
  6. Stage the .gitignore file using `sandbox.git.add(absoluteRepoDir, ['.gitignore'])`
  7. Commit changes using `sandbox.git.commit()` with bot user credentials from `process.env.GITHUB_APP_NAME`
  8. Push to remote using `sandbox.git.push(absoluteRepoDir, 'git', githubInstallationToken)`
  9. Set `newBranchName = 'main'` and emit success event for the clone action
- Ensure proper error handling with try-catch blocks and appropriate error messages via `emitStepEvent()`
- Continue with the normal execution flow after successful empty repo initialization
  • Task 2:
**Build the project and run linting/formatting**

Run the following commands from the repository root:
- `yarn build` to build all packages including the shared package and open-swe app
- `yarn lint:fix` to fix any linting issues
- `yarn format` to format the code according to project standards

Proceeding to implementation...

open-swe[bot] avatar Aug 06 '25 18:08 open-swe[bot]