Skip to content

CLI-715 better support for git worktrees during integration#547

Draft
sophio-japharidze-sonarsource wants to merge 2 commits into
masterfrom
CLI-715_better_worktree_support
Draft

CLI-715 better support for git worktrees during integration#547
sophio-japharidze-sonarsource wants to merge 2 commits into
masterfrom
CLI-715_better_worktree_support

Conversation

@sophio-japharidze-sonarsource

@sophio-japharidze-sonarsource sophio-japharidze-sonarsource commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Summary by Gitar

  • Git Worktree Support:
    • Created lib/project-workspace/git-worktree.ts to canonicalize paths and resolve main working tree roots.
    • Updated analyze agentic to check both current and main working tree paths for project metadata.
  • State Persistence:
    • Modified integrate commands to persist repoRoot (the main working tree) in state attributes, decoupling it from the physical targetRoot.
    • Updated sonar context to match current paths against either repoRoot or targetRoot, ensuring state persists across linked worktree creation.
  • Testing:
    • Added integration tests in context-augmentation.test.ts and analyze-sqaa.test.ts to verify cross-worktree state resolution.
  • Documentation:
    • Updated CLAUDE.md to detail worktree-aware resolution logic for SQAA and Context Augmentation.

This will update automatically on new commits.

@netlify

netlify Bot commented Jul 2, 2026

Copy link
Copy Markdown

Deploy Preview for sonarqube-cli ready!

Name Link
🔨 Latest commit 8d11497
🔍 Latest deploy log https://app.netlify.com/projects/sonarqube-cli/deploys/6a4cdf678bdcdd000831f41e
😎 Deploy Preview https://deploy-preview-547--sonarqube-cli.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@hashicorp-vault-sonar-prod

hashicorp-vault-sonar-prod Bot commented Jul 2, 2026

Copy link
Copy Markdown

CLI-715

@sophio-japharidze-sonarsource sophio-japharidze-sonarsource force-pushed the CLI-715_better_worktree_support branch 3 times, most recently from 0f06306 to bc03827 Compare July 6, 2026 11:29
Comment thread tests/integration/specs/integrate/context-augmentation.test.ts Outdated
@sophio-japharidze-sonarsource sophio-japharidze-sonarsource force-pushed the CLI-715_better_worktree_support branch from bc03827 to 0aaf2b4 Compare July 6, 2026 11:32
@sophio-japharidze-sonarsource sophio-japharidze-sonarsource force-pushed the CLI-715_better_worktree_support branch from 0aaf2b4 to 4cf9c21 Compare July 6, 2026 11:36
Comment on lines +29 to +34
/**
* The current working tree's root, passed to CAG so it can locate (or lazily
* create) the per-workspace daemon folder from any git worktree. Set only when
* the repository's main working tree has a recorded integration.
*/
workspaceDir?: string;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Quality: workspaceDir doc says "current working tree" but value is main tree

The workspaceDir field's doc comment in context-augmentation-env.ts describes it as "The current working tree's root". However, the value actually assigned (in resolveRecordedContextAugmentationConfig, context/index.ts:156) is getOptionalStringAttr(match.attrs, 'repoRoot') ?? match.targetRoot — i.e. the recorded main working tree / integrated folder, deliberately NOT the current working tree. The context/index.ts comment correctly explains this ('the stable main-working-tree key ... correct from any subfolder or linked worktree'). This is the whole point of the change: CAG resolves the same workspace regardless of which linked worktree it is invoked from. The interface comment contradicts that intent and could mislead a future reader into thinking the current worktree is passed. Suggest aligning the comment with the actual semantics (the repository's main working tree / recorded integrated folder).

Correct the comment to describe the main working tree, matching the value actually passed.:

/**
 * The repository's main working tree (the recorded integrated folder), passed
 * to CAG so it can locate (or lazily create) the per-workspace daemon folder
 * consistently from any git worktree. Set only when the repository's main
 * working tree has a recorded integration.
 */
workspaceDir?: string;
  • Apply fix

Check the box to apply the fix or reply for a change | Was this helpful? React with 👍 / 👎

@gitar-bot

gitar-bot Bot commented Jul 7, 2026

Copy link
Copy Markdown
Code Review 👍 Approved with suggestions 1 resolved / 2 findings

Improves Git worktree support by decoupling repo root from physical target paths and ensuring state consistency across branches. Please update the workspaceDir documentation to clarify that it references the main working tree rather than the current one.

💡 Quality: workspaceDir doc says "current working tree" but value is main tree

📄 src/cli/commands/_common/context-augmentation-env.ts:29-34 📄 src/cli/commands/context/index.ts:151-156

The workspaceDir field's doc comment in context-augmentation-env.ts describes it as "The current working tree's root". However, the value actually assigned (in resolveRecordedContextAugmentationConfig, context/index.ts:156) is getOptionalStringAttr(match.attrs, 'repoRoot') ?? match.targetRoot — i.e. the recorded main working tree / integrated folder, deliberately NOT the current working tree. The context/index.ts comment correctly explains this ('the stable main-working-tree key ... correct from any subfolder or linked worktree'). This is the whole point of the change: CAG resolves the same workspace regardless of which linked worktree it is invoked from. The interface comment contradicts that intent and could mislead a future reader into thinking the current worktree is passed. Suggest aligning the comment with the actual semantics (the repository's main working tree / recorded integrated folder).

Correct the comment to describe the main working tree, matching the value actually passed.
/**
 * The repository's main working tree (the recorded integrated folder), passed
 * to CAG so it can locate (or lazily create) the per-workspace daemon folder
 * consistently from any git worktree. Set only when the repository's main
 * working tree has a recorded integration.
 */
workspaceDir?: string;
✅ 1 resolved
Quality: Test comment misstates production canonicalization behavior

📄 tests/integration/specs/integrate/context-augmentation.test.ts:44-55 📄 src/lib/project-workspace/git-worktree.ts:37-43
The new canonical() test helper comment (tests/integration/specs/integrate/context-augmentation.test.ts:44-46) states it mirrors "the production canonicalization (realpathSync.native + lowercase on Windows)". However, production canonicalize() in src/lib/project-workspace/git-worktree.ts:37-43 only calls realpathSync.native(path) and does NOT lowercase. The tests stay internally consistent because both sides of each assertion pass through the same helper, but the comment could mislead a future reader into thinking production lowercases paths (it relies on realpathSync.native returning canonical drive-letter casing instead). Suggest correcting the comment to reflect that the lowercasing is a test-only normalization that is at least as tolerant as production.

🤖 Prompt for agents
Code Review: Improves Git worktree support by decoupling repo root from physical target paths and ensuring state consistency across branches. Please update the `workspaceDir` documentation to clarify that it references the main working tree rather than the current one.

1. 💡 Quality: workspaceDir doc says "current working tree" but value is main tree
   Files: src/cli/commands/_common/context-augmentation-env.ts:29-34, src/cli/commands/context/index.ts:151-156

   The `workspaceDir` field's doc comment in `context-augmentation-env.ts` describes it as "The current working tree's root". However, the value actually assigned (in `resolveRecordedContextAugmentationConfig`, `context/index.ts:156`) is `getOptionalStringAttr(match.attrs, 'repoRoot') ?? match.targetRoot` — i.e. the recorded *main* working tree / integrated folder, deliberately NOT the current working tree. The context/index.ts comment correctly explains this ('the stable main-working-tree key ... correct from any subfolder or linked worktree'). This is the whole point of the change: CAG resolves the same workspace regardless of which linked worktree it is invoked from. The interface comment contradicts that intent and could mislead a future reader into thinking the current worktree is passed. Suggest aligning the comment with the actual semantics (the repository's main working tree / recorded integrated folder).

   Fix (Correct the comment to describe the main working tree, matching the value actually passed.):
   /**
    * The repository's main working tree (the recorded integrated folder), passed
    * to CAG so it can locate (or lazily create) the per-workspace daemon folder
    * consistently from any git worktree. Set only when the repository's main
    * working tree has a recorded integration.
    */
   workspaceDir?: string;

Options

Auto-apply is off → Gitar will not commit updates to this branch.
Display: compact → Showing less information.

Comment with these commands to change the behavior for this request:

Auto-apply Compact
gitar auto-apply:on         
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Gitar

@sonarqubecloud

sonarqubecloud Bot commented Jul 7, 2026

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant