Skip to content

fix(service-git)!: resolve selected files from the worktree root - #517

Draft
SaKaNa-Y wants to merge 4 commits into
devframes:mainfrom
SaKaNa-Y:fix/git-service-nested-paths
Draft

SaKaNa-Y wants to merge 4 commits into
devframes:mainfrom
SaKaNa-Y:fix/git-service-nested-paths

Conversation

@SaKaNa-Y

@SaKaNa-Y SaKaNa-Y commented Dec 1, 2026 •

Copy link
Copy Markdown
Member

Summary

When the Git dashboard starts in packages/app, both the root and the package can have a modified README.md. The root row could show the package edit, and its Stage button could add the package README to the index. Selecting both rows could fail because Git looked for packages/app/packages/app/README.md.

The Git service now resolves each status path from the worktree root. An explicit path such as ./README.md still selects the file in the package. Preview, history, stage and unstage use this rule and treat filenames literally, so a route named pages/[id].tsx can be selected on its own. If two repositories share a worktree, each operation uses the repository opened by the service.

Breaking

Callers that used README.md for a file in the service directory should pass ./README.md or its full repository-relative path. Pass a directory or an explicit list of paths for a group. Callers that used Git patterns must expand them first. Passing . to stage or unstage still selects the service directory.

Evidence

Action from packages/app Before After
Preview and stage the root README Package patch and index entry Root patch and index entry
Stage both status rows Git path error Both files staged
With both staged, unstage the root README Root file remained staged Package file remained staged
  • Clicked the Changes panel in Chromium and checked the native Git index after each action. Also checked the public Node and WebSocket interfaces from the root and the package.
  • Verified stage, unstage and filtered history with 8,000 status paths and with mixed lists of root and package paths. Native Git confirmed every index entry.
  • Five regression tests failed on the base commit. All 23 Git service tests passed on this branch, including the case where two indexes share a worktree. The full suite passed (1,919 passed, 14 skipped). Build, typecheck, ESLint, Knip and docs lint passed.

Merge Danger

Door · The code can be reverted. Recovering an overwritten staged version may require finding its unreferenced Git object.

Blast radius · High for index writes. Choosing the wrong file or repository can replace a staged version that differs from both the working file and its last commit. With two indexes sharing a worktree, unstaging the file now preserves the staged version in the other index.

A dashboard started in a package directory lists paths from the worktree
root. Passing those paths back to Git could preview or stage a different
file with the same name.

Run file operations with literal paths from the appropriate directory.
Keep explicit cwd-relative paths in mixed requests and preserve the
spelling of filenames in history and committed file reads.

BREAKING CHANGE: Bare filenames in a nested Git service select files at
the worktree root. Use ./ to select a file in the service directory.
For multiple files, pass a directory or an explicit list of filenames
instead of a Git pathspec pattern.
@vercel

vercel Bot commented Dec 1, 2026

Copy link
Copy Markdown

@SaKaNa-Y is attempting to deploy a commit to the NuxtLabs Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions

github-actions Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

👁️‍🗨️ Review this pull request with grouped, summarized diffs at:
👉 https://pulls.review/gh/devframes/devframe/517?from=github-actions[bot]

raw result

💭 analyzed by vercel-ai-gateway/anthropic/claude-sonnet-5
🕰️ 2026-12-01 14:51 UTC
🔗 head 0b5feb6
🤖 automated by pulls.review

{
  "headSha": "0b5feb6a44004a0fc0496e04a5934cd36fbb8893",
  "result": {
    "overallSummary": "Fixes a bug where the Git service, started from a nested package directory, could confuse a root file with a same-named package file (e.g. two `README.md`), leading to the wrong file being previewed or staged/unstaged, or an outright path error when both were selected. The fix makes file selection literal and resolved relative to the worktree root or the configured cwd, with new tests covering the collision scenarios and documentation of the (breaking) path semantics.",
    "groups": [
      {
        "key": "path-resolution",
        "label": "Resolve paths from worktree root",
        "summary": "Reworks how the Git service resolves `stage`, `unstage`, `diff`, `log` and `readFile` paths so they are interpreted literally and relative to the worktree root instead of being naively prefixed with the service's cwd, fixing collisions between a root file and a same-named file in a nested package.",
        "category": "core",
        "filePaths": [
          "services/git/src/git.ts",
          "services/git/src/operations.ts",
          "services/git/src/types.ts"
        ],
        "critical": true,
        "fileNotes": [
          {
            "path": "services/git/src/git.ts",
            "text": "Core of the fix: `fileSelection` decides whether to run Git from the repo root or the configured cwd (to preserve relative GIT_* env settings), rewrites paths accordingly, and `fileArgs` builds literal, non-glob pathspec arguments.",
            "critical": true
          },
          {
            "path": "services/git/src/operations.ts",
            "text": "`stage`/`unstage` are unified through a new `updateIndex` helper, and `log`/`diff`/`readFile` now go through `fileSelection`/`fileArgs` instead of trimming and appending raw paths after `--`."
          }
        ]
      },
      {
        "key": "tests",
        "label": "Tests for path selection",
        "summary": "Adds repo fixtures (edited files across root/package, shared worktrees) and tests covering root-vs-package collisions, literal bracket/space filenames, relative Git env settings, and shared-worktree index selection.",
        "category": "tests",
        "filePaths": [
          "services/git/test/_repo.ts",
          "services/git/test/git.test.ts"
        ],
        "fileNotes": [
          {
            "path": "services/git/test/_repo.ts",
            "text": "New `createEditedRepo` and `createSharedWorktreeRepo` helpers simulate a package nested inside the root repo, including a second Git directory sharing the outer worktree."
          }
        ]
      },
      {
        "key": "docs",
        "label": "Document path semantics",
        "summary": "Documents the new literal, root/cwd-relative path semantics for `diff`, `log`, `readFile`, `stage` and `unstage`.",
        "category": "docs",
        "filePaths": [
          "docs/content/5.add-ons/2.services/2.git.md"
        ]
      }
    ],
    "schemaVersion": 1,
    "source": "llm",
    "generatedAt": "2026-12-01T14:51:16.566Z",
    "model": "vercel-ai-gateway/anthropic/claude-sonnet-5",
    "locale": "en"
  }
}

Keep the Git subprocess in its original directory so relative worktree and index settings apply to the same repository. Anchor repository-relative filenames with Git pathspecs and preserve the configured diff headers for explicit and absolute package paths.
Pass groups from one directory to Git in their original spelling. For mixed groups, use Git’s own relative directory prefix and keep relative Git worktree and index settings bound to the service directory. Literal file arguments also retain Git’s normal handling of redundant path separators and dot components.
Keep root-based selections in the Git directory discovered from the service directory when different indexes share a worktree. For mixed selections, choose the base that adds fewer bytes to the Git arguments.

This branch has not been deployed

No deployments
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