Skip to content

fix(skills): resolve's repo-detection fallback regex retains .git suffix - #2362

Merged
carlos-alm merged 2 commits into
mainfrom
fix/issue-2186-resolve-repo-regex
Aug 8, 2026
Merged

carlos-alm merged 2 commits into
mainfrom
fix/issue-2186-resolve-repo-regex

Conversation

@carlos-alm

Copy link
Copy Markdown
Contributor

Summary

Closes #2186

Greptile caught the identical flaw in PR #2185 while reviewing the same fallback pattern being added to /sweep. /resolve had it in two places (gh repo view's fallback, only exercised when gh isn't authenticated):

REPO=$(gh repo view --json nameWithOwner -q .nameWithOwner 2>/dev/null \
  || git remote get-url origin | sed -E 's|.*github\.com[:/](.+)(\.git)?$|\1|')
  1. The greedy (.+) capture swallows .git before the optional (\.git)? group ever gets a chance to match it, so a standard https://github.com/owner/repo.git or git@github.com:owner/repo.git remote resolves to owner/repo.git instead of owner/repo — every subsequent gh --repo call in the skill then targets an invalid slug.
  2. When origin isn't a github.com URL at all, plain sed 's|pattern|replacement|' leaves a non-matching line unchanged, so the raw (wrong) URL becomes $REPO — non-empty, so the existing -z guard doesn't catch it, and the skill proceeds with a garbage repo identifier instead of failing loudly.

Fix

Mirrors the exact fix already applied to /sweep in PR #2185: a two-pass sed (non-greedy quantifiers aren't POSIX ERE — +? errors on BSD sed's -E and isn't GNU-portable either). The first pass only prints when the URL is a genuine github.com remote (so a non-GitHub origin correctly produces empty output, caught by the -z guard); the second unconditionally strips a trailing .git, sidestepping the greedy-capture problem entirely.

Test plan

  • Verified the new regex against https://github.com/owner/repo.git, git@github.com:owner/repo.git, https://github.com/owner/repo (no suffix), and a non-GitHub remote (https://gitlab.com/owner/repo.git) — all four resolve correctly (owner/repo, owner/repo, owner/repo, empty respectively).
  • .claude/skills/create-skill/scripts/lint-skill.sh against this file: same pre-existing errors, plus the same 2>/dev/null-without-comment warning already present (and unaddressed) on the identical construct in /sweep's already-merged version — no new issue class introduced.

Closes #2186

Greptile caught the identical flaw in PR #2185 while reviewing the same
fallback pattern being added to /sweep. /resolve had it in two places
(gh repo view's fallback when gh isn't authenticated):

  REPO=$(gh repo view --json nameWithOwner -q .nameWithOwner 2>/dev/null \
    || git remote get-url origin | sed -E 's|.*github\.com[:/](.+)(\.git)?$|\1|')

1. The greedy (.+) capture swallows .git before the optional (\.git)?
   group ever matches it, so a standard https://.../repo.git or
   git@github.com:owner/repo.git remote resolves to "owner/repo.git"
   instead of "owner/repo" — every subsequent gh --repo call then targets
   an invalid slug.
2. When origin isn't a github.com URL at all, plain `sed 's|pattern|
   replacement|'` leaves a non-matching line unchanged, so the raw (wrong)
   URL becomes $REPO — non-empty, so the existing `-z` guard doesn't catch
   it, and the skill proceeds with a garbage repo identifier instead of
   failing loudly.

Mirrors the exact fix already applied to /sweep in PR #2185: a two-pass
sed (non-greedy quantifiers aren't POSIX ERE — `+?` errors on BSD sed's
-E and isn't GNU-portable either). The first pass only prints when the
URL is a genuine github.com remote (so a non-GitHub origin correctly
produces empty output, caught by the -z guard); the second unconditionally
strips a trailing .git, sidestepping the greedy-capture problem entirely.
@greptile-apps

greptile-apps Bot commented Aug 8, 2026 •

Copy link
Copy Markdown
Contributor

Greptile Summary

The fallback repository detection now accepts both SCP-style and ssh:// GitHub remotes while removing a trailing .git suffix and rejecting non-GitHub URLs.

  • Updates both /resolve repository-detection paths consistently.
  • The previously reported rejection of ssh://git@github.com/owner/repo is fixed.

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains.

Important Files Changed

Filename Overview
.claude/skills/resolve/SKILL.md Both fallback commands now recognize supported GitHub SSH and HTTPS remote formats, extract the owner/repository slug, and strip .git.

Reviews (2): Last reviewed commit: "fix(skills): resolve fallback regex also..." | Re-trigger Greptile

|| git remote get-url origin | sed -E 's|.*github\.com[:/](.+)(\.git)?$|\1|')
|| git remote get-url origin 2>/dev/null \
| sed -nE 's#^(git@github\.com:|https://github\.com/)([^/]+/[^/]+)/?$#\2#p' \
| sed -E 's/\.git$//')

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.

P1 GitHub SSH URLs are rejected

When gh repo view fails and origin uses a valid URL such as ssh://git@github.com/owner/repo, the new anchored expression emits an empty slug, causing /resolve to terminate even though the previous fallback resolved that remote.

Fix in Claude Code

Greptile flagged (PR #2362) that the anchored two-pass sed only accepted
git@github.com:owner/repo and https://github.com/owner/repo, silently
rejecting ssh://git@github.com/owner/repo — a valid GitHub remote URL
form the OLD (buggy) regex happened to accept via its permissive prefix
match. A genuine regression, not a pre-existing gap. Added it as a third
alternative in the prefix group.

Filed #2363 for the identical gap in /sweep's PR #2185, the original
source of this fallback pattern — out of scope for this PR.
@carlos-alm

Copy link
Copy Markdown
Contributor Author

@greptileai

@carlos-alm
carlos-alm merged commit 511744f into main Aug 8, 2026
23 checks passed
@carlos-alm
carlos-alm deleted the fix/issue-2186-resolve-repo-regex branch August 8, 2026 14:09
@github-actions github-actions Bot locked and limited conversation to collaborators Aug 8, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

chore: /resolve's repo-detection fallback regex retains .git suffix and accepts non-GitHub remotes

1 participant