Skip to content

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

Closed

Description

@carlos-alm

Summary

Greptile caught this bug in PR #2185 while reviewing a copy of this same fallback pattern added to `/sweep`. `.claude/skills/resolve/SKILL.md` has the identical, pre-existing flaw in 2 places (lines 62 and 81):

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

Two issues with the fallback (only exercised when `gh repo view` fails, e.g. `gh` unauthenticated):

  1. Retains the `.git` suffix. 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. Silently accepts non-GitHub remotes. 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 is returned as $REPO — non-empty, so the existing `if [ -z "$REPO" ]` guard doesn't catch it, and the skill proceeds with a garbage repo identifier instead of failing loudly.

Suggested fix

Mirror the fix applied to `/sweep` in PR #2185 — a two-pass `sed`, since non-greedy quantifiers aren't POSIX ERE (confirmed: `+?` errors on both BSD sed's `-E` and is not GNU-portable either):

```bash
REPO=$(gh repo view --json nameWithOwner -q .nameWithOwner 2>/dev/null
|| git remote get-url origin 2>/dev/null
| sed -nE 's#^(git@github.com:|https://github\.com/)([^/]+/[^/]+)/?$#\2#p'
| sed -E 's/.git$//')
```

The first pass only prints (`-n ... p`) when the URL is a genuine `github.com` remote, so a non-GitHub `origin` correctly produces empty output (caught by the existing `-z` guard) instead of passing through unchanged. The second pass unconditionally strips a trailing `.git`, sidestepping the greedy-capture problem entirely.

Filed separately per scope-discipline convention — out of scope for #1966 (which covered the hardcoded-wrong-repo-name bug, not this regex correctness issue), and `/resolve` wasn't touched by PR #2185's diff.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions