Skip to content

Fix apply_samples cross-repo subdirectory patch staging (#40086)#40087

Merged
dsyme merged 2 commits into
mainfrom
fix/apply-samples-cross-repo-subdir-40086
Jun 18, 2026
Merged

Fix apply_samples cross-repo subdirectory patch staging (#40086)#40087
dsyme merged 2 commits into
mainfrom
fix/apply-samples-cross-repo-subdir-40086

Conversation

@dsyme

@dsyme dsyme commented Jun 18, 2026

Copy link
Copy Markdown
Collaborator

Summary

Fixes #40086. After #40080 unmasked it, gh aw compile --use-samples replay
fails with Failed to pin branch '...': ERR_SYSTEM: fatal: Needed a single revision
when a create_pull_request / push_to_pull_request_branch sample patch targets
a cross-repo checkout placed in a subdirectory (path: github).

Root cause

apply_samples.cjs's preStagePatch always created the sample branch and
committed the patch in the main workspace root (GITHUB_WORKSPACE). For a
cross-repo checkout in a subdirectory, the safe-outputs MCP handler resolves the
target repo to ${GITHUB_WORKSPACE}/github via the checkout manifest and looks
for the branch there — but the branch was created in the root, so pinning failed.

Fix

apply_samples.cjs:

  • readConfiguredTargetRepo(tool) — reads the per-tool target-repo from the
    safe-outputs config (GH_AW_SAFE_OUTPUTS_CONFIG_PATH).
  • resolvePatchWorkspace(entry, workspace) — resolves the on-disk checkout
    directory for the target repo using the same manifest-first findRepoCheckout
    the MCP handler uses (target repo from 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 can't be located.
  • preStagePatch now stages the branch/commit in that resolved directory instead
    of always the root.

Tests

  • Added a regression test reproducing the path: github side-repo layout,
    asserting the branch/commit/file land in the subdirectory and not the main
    repo root.

Validation

  • All JS tests pass (23 in apply_samples.test.cjs), typecheck + prettier pass.
  • Go samples-replay tests pass; the driver bundles cleanly with the new dependency.

…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.
Copilot AI review requested due to automatic review settings June 18, 2026 15:07
@github-actions

github-actions Bot commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Comment Memory

CI lights the path
Green checks bloom at dawn
Quiet bots still sing

Note

This comment is managed by comment memory.

It stores persistent context for this thread in the code block at the top of this comment.
Edit only the text inside the backtick fences; workflow metadata and the footer are regenerated automatically.

Learn more about comment memory

Generated by 🧪 Smoke CI for issue #40087 ·

Copilot AI 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.

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() and resolvePatchWorkspace() 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

Comment thread actions/setup/js/apply_samples.cjs
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@dsyme dsyme merged commit bb2a018 into main Jun 18, 2026
11 checks passed
@dsyme dsyme deleted the fix/apply-samples-cross-repo-subdir-40086 branch June 18, 2026 15:22
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.

apply_samples: preStagePatch creates sample branch in wrong directory for subdirectory cross-repo checkouts (path: github)

2 participants