-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Disable checkpoint if nested git repos are detected #4509
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -380,8 +380,8 @@ describe.each([[RepoPerTaskCheckpointService, "RepoPerTaskCheckpointService"]])( | |
| }) | ||
| }) | ||
|
|
||
| describe(`${klass.name}#renameNestedGitRepos`, () => { | ||
| it("handles nested git repositories during initialization", async () => { | ||
| describe(`${klass.name}#hasNestedGitRepositories`, () => { | ||
| it("throws error when nested git repositories are detected during initialization", async () => { | ||
| // Create a new temporary workspace and service for this test. | ||
| const shadowDir = path.join(tmpDir, `${prefix}-nested-git-${Date.now()}`) | ||
| const workspaceDir = path.join(tmpDir, `workspace-nested-git-${Date.now()}`) | ||
|
|
@@ -417,11 +417,7 @@ describe.each([[RepoPerTaskCheckpointService, "RepoPerTaskCheckpointService"]])( | |
| const nestedGitDir = path.join(nestedRepoPath, ".git") | ||
| const headFile = path.join(nestedGitDir, "HEAD") | ||
| await fs.writeFile(headFile, "HEAD") | ||
| const nestedGitDisabledDir = `${nestedGitDir}_disabled` | ||
| expect(await fileExistsAtPath(nestedGitDir)).toBe(true) | ||
| expect(await fileExistsAtPath(nestedGitDisabledDir)).toBe(false) | ||
|
|
||
| const renameSpy = jest.spyOn(fs, "rename") | ||
|
|
||
| jest.spyOn(fileSearch, "executeRipgrep").mockImplementation(({ args }) => { | ||
| const searchPattern = args[4] | ||
|
|
@@ -440,29 +436,48 @@ describe.each([[RepoPerTaskCheckpointService, "RepoPerTaskCheckpointService"]])( | |
| }) | ||
|
|
||
| const service = new klass(taskId, shadowDir, workspaceDir, () => {}) | ||
| await service.initShadowGit() | ||
|
|
||
| // Verify rename was called with correct paths. | ||
| expect(renameSpy.mock.calls).toHaveLength(1) | ||
| expect(renameSpy.mock.calls[0][0]).toBe(nestedGitDir) | ||
| expect(renameSpy.mock.calls[0][1]).toBe(nestedGitDisabledDir) | ||
| // Verify that initialization throws an error when nested git repos are detected | ||
| await expect(service.initShadowGit()).rejects.toThrow( | ||
| "Checkpoints are disabled because nested git repositories were detected in the workspace", | ||
| ) | ||
|
|
||
| jest.spyOn(require("../../../utils/fs"), "fileExistsAtPath").mockImplementation((path) => { | ||
| if (path === nestedGitDir) { | ||
| return Promise.resolve(true) | ||
| } else if (path === nestedGitDisabledDir) { | ||
| return Promise.resolve(false) | ||
| } | ||
| // Clean up. | ||
| jest.restoreAllMocks() | ||
| await fs.rm(shadowDir, { recursive: true, force: true }) | ||
| await fs.rm(workspaceDir, { recursive: true, force: true }) | ||
| }) | ||
|
|
||
| it("succeeds when no nested git repositories are detected", async () => { | ||
| // Create a new temporary workspace and service for this test. | ||
| const shadowDir = path.join(tmpDir, `${prefix}-no-nested-git-${Date.now()}`) | ||
| const workspaceDir = path.join(tmpDir, `workspace-no-nested-git-${Date.now()}`) | ||
|
|
||
| // Create a primary workspace repo without any nested repos. | ||
| await fs.mkdir(workspaceDir, { recursive: true }) | ||
| const mainGit = simpleGit(workspaceDir) | ||
| await mainGit.init() | ||
| await mainGit.addConfig("user.name", "Roo Code") | ||
| await mainGit.addConfig("user.email", "[email protected]") | ||
|
|
||
| return Promise.resolve(false) | ||
| // Create a test file in the main workspace. | ||
| const mainFile = path.join(workspaceDir, "main-file.txt") | ||
| await fs.writeFile(mainFile, "Content in main repo") | ||
| await mainGit.add(".") | ||
| await mainGit.commit("Initial commit in main repo") | ||
|
|
||
| jest.spyOn(fileSearch, "executeRipgrep").mockImplementation(() => { | ||
| // Return empty array to simulate no nested git repos found | ||
| return Promise.resolve([]) | ||
| }) | ||
|
|
||
| // Verify the nested git directory is back to normal after initialization. | ||
| expect(await fileExistsAtPath(nestedGitDir)).toBe(true) | ||
| expect(await fileExistsAtPath(nestedGitDisabledDir)).toBe(false) | ||
| const service = new klass(taskId, shadowDir, workspaceDir, () => {}) | ||
|
|
||
| // Verify that initialization succeeds when no nested git repos are detected | ||
| await expect(service.initShadowGit()).resolves.not.toThrow() | ||
| expect(service.isInitialized).toBe(true) | ||
|
|
||
| // Clean up. | ||
| renameSpy.mockRestore() | ||
| jest.restoreAllMocks() | ||
| await fs.rm(shadowDir, { recursive: true, force: true }) | ||
| await fs.rm(workspaceDir, { recursive: true, force: true }) | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is user-facing right? Should probably internationalize.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not currently user facing; it just shows up in the logs. I posed the question about surfacing this to users above; it sounds like you'd be supportive of that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do this as a follow-up.