Skip to content

made the diff-target fallbacks run and anchored the issue key - #20

Merged
malav2110 merged 5 commits into
malav2110:mainfrom
andyhorn:upstream-diff-target-resolution
Oct 14, 2026
Merged

malav2110 merged 5 commits into
malav2110:mainfrom
andyhorn:upstream-diff-target-resolution

Conversation

@andyhorn

@andyhorn andyhorn commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

Fixes the fallbacks step 1 uses to decide what to diff, and the issue-key pattern that names the output file.

Changes

  • Default-branch lookup. ${base:-origin/$(git remote show origin | sed …)} produced the non-empty string origin/ when the network call failed, so the documented origin/main or origin/master fallback never ran and the diff failed on a bad ref. The snippet now adds origin/ only to a non-empty answer, codes the main/master fallback, and stops with no default branch found if every attempt fails.
  • Pull request base in the git form.
    • When baseRefOid couldn't be fetched, the fallback fetched the base branch, but the diff still named the unfetchable sha. It now diffs from the merge base of the fetched branch and the head.
    • A final check stops on an empty diff instead of drafting a blank page.
    • The text now says the git form still needs gh for the base lookup, and that without gh the skill should ask for the base commit.
  • Issue-key pattern. (issue|gh|#)[-_]?[0-9]+ matched inside words, so fix-high-5 was keyed gh-5. The label must now start the branch name or follow /, -, or _.

Verification

  • The default-branch snippet was run in a scratch repo with an unreachable remote. It resolves origin/HEAD when present, falls back to origin/master, and stops cleanly when nothing exists.
  • The issue-key pattern was run on several names: fix-high-5 and xgh-4 give no key, and issue-12-x, feat/gh-7, and #33-fix give issue-12, gh-7, and #33.

For the reviewer

  • The pull request fallback was checked in pieces, not end to end, because reproducing a refused sha fetch needs a GitHub Enterprise server or a force-pushed base.

🤖 Generated with Claude Code

andyhorn and others added 2 commits October 5, 2026 12:26
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@malav2110 malav2110 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Thanks Andy! I ran the fallbacks in throwaway repos against main and this branch. With the remote down, the code on main sets the base to origin/, and this branch falls back to origin/main or origin/master.

One non-blocking suggestion inline, with a tested fix.

Comment thread skills/explain-diff-html/SKILL.md Outdated
… base

Without gh, git fetch origin "" fetched the default branch, so a pull
request into any other branch got the wrong base and passed the
empty-diff check.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017Lw3wPhG7pfdMoT8Y6D5YZ

@malav2110 malav2110 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Thanks for the quick turnaround, Andy! I ran the new commit in a throwaway repo with a PR into a non-default branch. Without gh it now stops with STOP: no base commit instead of diffing against the wrong base. An unfetchable sha still falls back to the merge base. One non-blocking suggestion inline, for when the base branch is gone too.

Comment thread skills/explain-diff-html/SKILL.md Outdated
Comment on lines +223 to +224
if [ -z "$pr_base" ] || ! git fetch origin "$pr_base"; then
# The sha is unreachable or refused: diff from where the head left the base branch.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

suggestion (non-blocking): Clearing pr_base here lets STOP: no base commit also catch the case where the base sha and the base branch both fail to fetch. Right now pr_base keeps the sha from gh, so the agent sees bad object and then the empty-diff STOP. The cases you listed still come out the same, and the new comment covers the no-gh case too.

Suggested change
if [ -z "$pr_base" ] || ! git fetch origin "$pr_base"; then
# The sha is unreachable or refused: diff from where the head left the base branch.
if [ -z "$pr_base" ] || ! git fetch origin "$pr_base"; then
# No sha from gh, or the server refused it: diff from where the head left the base branch.
pr_base=""

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Applied in 3c5d012. STOP: no base commit now also fires when the base sha and the base branch both fail to fetch. I tested it with git fetch stubbed to fail.

@malav2110

malav2110 commented Oct 13, 2026 •

Copy link
Copy Markdown
Owner

Hey @andyhorn , do you want to pick up the last suggestion, or should I commit it and merge?

…gone base branch

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01T58NPz2J74Vkr1ABminq2L
@malav2110

Copy link
Copy Markdown
Owner

Thanks @andyhorn ! I re-ran it in a throwaway repo with the base sha and the base branch both gone, and it now stops with STOP: no base commit. The other fallbacks still come out the same. Merging now.

@malav2110
malav2110 merged commit 9950cf8 into malav2110:main Oct 14, 2026
1 check passed
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.

2 participants