Fix apply_samples cross-repo subdirectory patch staging (#40086)#40087
Conversation
…ut (#40086) apply_samples.cjs always created the sample branch and committed the patch in the main workspace root. For a cross-repo checkout placed in a subdirectory (path: github), the safe-outputs MCP handler resolves the target repo to the subdirectory via the checkout manifest and looks for the branch there, so it failed with 'fatal: Needed a single revision'. Resolve the patch-staging directory using the same manifest-first findRepoCheckout the MCP handler uses, driven by the sample's arguments.repo override or the configured target-repo. Falls back to the workspace root when no target repo is set or the checkout cannot be located.
Comment MemoryNote This comment is managed by comment memory.It stores persistent context for this thread in the code block at the top of this comment.
|
There was a problem hiding this comment.
Pull request overview
This pull request fixes gh aw compile --use-samples replay failures when a create_pull_request / push_to_pull_request_branch sample patch targets a cross-repo checkout located in a workspace subdirectory (e.g. path: github). It does so by resolving the correct on-disk checkout directory (via the checkout manifest) and staging the sample branch + commit in that checkout instead of always using the workspace root.
Changes:
- Add
readConfiguredTargetRepo()andresolvePatchWorkspace()to determine the correct repo checkout directory for staging sample patches. - Update
preStagePatch()to run all git operations in the resolved checkout directory. - Add a regression test covering cross-repo subdirectory layouts and a changeset entry.
Show a summary per file
| File | Description |
|---|---|
| actions/setup/js/apply_samples.cjs | Resolve target checkout directory for patch staging and stage branches/commits in that repo directory. |
| actions/setup/js/apply_samples.test.cjs | Add regression test ensuring branches/commits/files land in the subdirectory checkout, not the workspace root. |
| .changeset/patch-apply-samples-cross-repo-subdir-staging.md | Document the patch-level fix in release notes. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 3/3 changed files
- Comments generated: 1
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Summary
Fixes #40086. After #40080 unmasked it,
gh aw compile --use-samplesreplayfails with
Failed to pin branch '...': ERR_SYSTEM: fatal: Needed a single revisionwhen a
create_pull_request/push_to_pull_request_branchsample patch targetsa cross-repo checkout placed in a subdirectory (
path: github).Root cause
apply_samples.cjs'spreStagePatchalways created the sample branch andcommitted the patch in the main workspace root (
GITHUB_WORKSPACE). For across-repo checkout in a subdirectory, the safe-outputs MCP handler resolves the
target repo to
${GITHUB_WORKSPACE}/githubvia the checkout manifest and looksfor the branch there — but the branch was created in the root, so pinning failed.
Fix
apply_samples.cjs:readConfiguredTargetRepo(tool)— reads the per-tooltarget-repofrom thesafe-outputs config (
GH_AW_SAFE_OUTPUTS_CONFIG_PATH).resolvePatchWorkspace(entry, workspace)— resolves the on-disk checkoutdirectory for the target repo using the same manifest-first
findRepoCheckoutthe MCP handler uses (target repo from the sample's
arguments.repooverride orthe configured
target-repo). Falls back to the workspace root when no targetrepo is set or the checkout can't be located.
preStagePatchnow stages the branch/commit in that resolved directory insteadof always the root.
Tests
path: githubside-repo layout,asserting the branch/commit/file land in the subdirectory and not the main
repo root.
Validation
apply_samples.test.cjs), typecheck + prettier pass.