Skip to content

fix(cli): resolve workspaceDir and origin remoteUrl via git in worktrees - #5105

Closed
princejain756 wants to merge 1 commit into
triggerdotdev:mainfrom
princejain756:fix/worktree-git-meta-and-workspace
Closed

princejain756 wants to merge 1 commit into
triggerdotdev:mainfrom
princejain756:fix/worktree-git-meta-and-workspace

Conversation

@princejain756

@princejain756 princejain756 commented Nov 8, 2026 •

Copy link
Copy Markdown

Fixes #5103

In a linked git worktree, .git is a file (gitdir: /path/to/repo/.git/worktrees/<name>) rather than a directory, and remote.origin.url lives in the common repo config instead of the worktree dir. Because of that, createGitMeta failed to read origin and resolveWorkspaceDir walked past the worktree root up to whatever parent directory happened to have a .git folder or package.json.

Updated resolveWorkspaceDir to check git rev-parse first and resolveOriginUrl to fall back to git config when .git/config isn't a regular file in the worktree root. Added worktree tests in gitMeta.test.ts and config.test.ts.

@changeset-bot

changeset-bot Bot commented Nov 8, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 9f3b158

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@github-actions

github-actions Bot commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

Hi @princejain756, thanks for your interest in contributing!

This project requires that pull request authors are vouched, and you are not in the list of vouched users.

This PR will be closed automatically. See https://github.com/triggerdotdev/trigger.dev/blob/main/CONTRIBUTING.md for more details.

@github-actions github-actions Bot closed this Nov 8, 2026
@coderabbitai

coderabbitai Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Caution

Review failed

The pull request is closed.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Tip

🎯 Customize your risk assessments

Guide how CodeRabbit assesses merge risk and security architecture risk. Highlight sensitive changes and explain your security boundaries using Merge Risk Instructions and Security Risk Instructions in your review settings. Security architecture risk assessments require the Advanced plan or above.

✅ Automatic approvals, with your rules

Let CodeRabbit approve pull requests once required threads are resolved, pre-merge checks pass, and your risk limits are met. Enable Automatic approvals in review settings, with overrides for teams or file paths.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Devin Review found 5 potential issues.

Devin Review

const tsconfigPath = await safeResolveTsConfig(cwd);
const lockfilePath = await resolveLockfile(cwd);
const workspaceDir = await findWorkspaceDir(cwd);
const workspaceDir = (await getGitTopLevel(cwd)) ?? (await findWorkspaceDir(cwd));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Worktree fix absent from release notes

workspaceDir changes deployment behavior in linked worktrees, but this public CLI fix has no changeset. Customers cannot find the fix in release notes.

Learn more

This public CLI fix changes whether users can deploy from linked worktrees. The repository requires a patch changeset for user-facing bug fixes in public packages; none was added here. Without it, the release notes omit the fix.

Example: A user blocked from deploying in a nested worktree upgrades trigger.dev. The upgrade fixes their deployment, but the published changelog does not tell them about it.

Recommended fix: Add a patch changeset for trigger.dev describing the restored ability to deploy from linked Git worktrees in user-facing language.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Comment on lines +158 to +159
vi.stubEnv("GITHUB_ACTIONS", "");
vi.stubEnv("TRIGGER_GITHUB_APP", "");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Worktree tests stub CI state

Both new worktree tests use vi.stubEnv to disable CI detection. Repository testing rules ban stubs, so these tests violate the required test policy.

Learn more

The worktree integration tests mutate process-wide CI variables with vi.stubEnv, and the new cleanup calls vi.unstubAllEnvs. The repository's testing instructions explicitly prohibit stubs, even though the tests exercise real Git repositories.

Example: In a GitHub Actions run, the first worktree test replaces GITHUB_ACTIONS with an empty value before calling createGitMeta. It tests the local Git path by stubbing CI detection.

Recommended fix: Make the local Git metadata path testable without stubbing process environment, such as by passing an explicit environment or metadata source to the relevant function and using that option in both tests.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

const gitConfig = await parseGitConfig(configPath);
async function getOriginUrl(directory: string): Promise<string | null> {
try {
const result = await x("git", ["--no-optional-locks", "config", "--get", "remote.origin.url"], {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔍 Global Git origins now affect attribution

Without a repository origin, git config --get can read a global remote.origin.url. Deployment metadata then names that global remote instead of leaving the URL unset.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

return undefined;
}

return resolve(directory, cdup || ".");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟥 Symlinked projects upload outside files

For a symlink to a repository subdirectory, getGitTopLevel computes the wrong workspaceDir from Git's physical cdup. createContextArchive can then upload unrelated files, including secrets.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

const tsconfigPath = await safeResolveTsConfig(cwd);
const lockfilePath = await resolveLockfile(cwd);
const workspaceDir = await findWorkspaceDir(cwd);
const workspaceDir = (await getGitTopLevel(cwd)) ?? (await findWorkspaceDir(cwd));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟥 Nested workspace secrets enter deployment archives

For a nested workspace, workspaceDir now points to the outer Git root. createContextArchive skips the nested .gitignore and can upload secrets it excludes.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

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.

trigger deploy: wrong git metadata and build context from a git worktree

1 participant