-
Notifications
You must be signed in to change notification settings - Fork 8
Fix Git submodule being incorrectly identified as a worktree #129
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -63,6 +63,25 @@ describe('isWorktree', () => { | |
| const result = await isWorktree('/nonexistent/path') | ||
| assert.strictEqual(result, false) | ||
| }) | ||
|
|
||
| test('returns false for a submodule directory', async () => { | ||
| const subRepo = join(testDir, 'sub-repo') | ||
| const submodulePath = join(mainRepo, 'sub') | ||
|
|
||
| mkdirSync(subRepo, { recursive: true }) | ||
| execSync('git init -b main', { cwd: subRepo }) | ||
| writeFileSync(join(subRepo, 'sub.txt'), 'sub') | ||
| execSync('git add .', { cwd: subRepo }) | ||
| execSync('git commit -m "sub commit"', { cwd: subRepo }) | ||
|
|
||
| // Add submodule to main repo | ||
| execSync('git config --global protocol.file.allow always', { cwd: mainRepo }) | ||
| execSync(`git submodule add ${subRepo} sub`, { cwd: mainRepo }) | ||
|
Comment on lines
+78
to
+79
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔒 Security & Privacy | 🟡 Minor | ⚡ Quick win 🧩 Analysis chain🏁 Script executed: sed -n '1,220p' test/unit/git-worktree.test.jsRepository: athal7/opencode-devcontainers Length of output: 7385 Avoid global Git config and shell interpolation here
🧰 Tools🪛 OpenGrep (1.25.0)[ERROR] 79-79: Dynamic command passed to child_process.exec/execSync. Use child_process.execFile or spawn with an argument array instead. (coderabbit.command-injection.exec-js) 🤖 Prompt for AI AgentsSource: Linters/SAST tools |
||
| execSync('git commit -m "add submodule"', { cwd: mainRepo }) | ||
|
|
||
| const result = await isWorktree(submodulePath) | ||
| assert.strictEqual(result, false) | ||
| }) | ||
| }) | ||
|
|
||
| describe('getWorktreeMainRepo', () => { | ||
|
|
||
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.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
Repository: athal7/opencode-devcontainers
Length of output: 18821
🏁 Script executed:
Repository: athal7/opencode-devcontainers
Length of output: 18821
🏁 Script executed:
Repository: athal7/opencode-devcontainers
Length of output: 9175
Anchor the
gitdir:path to the repo’s own.git/worktrees/directory./[/\\]worktrees[/\\][^/\\]+\s*$also matches submodule admin dirs like.git/modules/worktrees/foo, so a submodule mounted atworktrees/foocan be misclassified as a worktree. Parse thegitdir:target and require it to live under the repository’s.git/worktrees/tree; add a regression test for a nestedworktrees/...submodule.🤖 Prompt for AI Agents