Skip to content

fix(tools): stop rstrip(".git") from mangling repository names - #174

Open
hobostay wants to merge 1 commit into
HKUDS:mainfrom
hobostay:fix/git-url-suffix-strip
Open

fix(tools): stop rstrip(".git") from mangling repository names#174
hobostay wants to merge 1 commit into
HKUDS:mainfrom
hobostay:fix/git-url-suffix-strip

Conversation

@hobostay

Copy link
Copy Markdown

Problem

GitHubURLExtractor in tools/git_command.py normalizes URLs with url.rstrip(".git") (two call sites: extract_github_urls() and infer_repo_name()).

str.rstrip() takes a set of characters, not a suffix — it strips any trailing combination of ., g, i, t. Any repository whose name ends in one of those characters gets truncated:

"https://github.com/facebook/react".rstrip(".git")     -> "https://github.com/facebook/reac"
"https://github.com/foo/deep-learning".rstrip(".git")  -> "https://github.com/foo/deep-learnin"
"https://github.com/org/project".rstrip(".git")        -> "https://github.com/org/projec"

The corrupted URL is then passed to git clone (fails with "repository not found", or worse, clones a different repo that exists under the truncated name), and infer_repo_name() derives a wrong target directory name.

Fix

Strip the trailing slash first, then remove only the real suffix:

url = url.rstrip("/")
url = url.removesuffix(".git")

(removesuffix requires Python 3.9+; the project requires >= 3.12.)

Tests

Added tests/test_git_command_url.py with regression tests covering:

  • repo names ending in t/g/... are preserved (facebook/react, deep-learning)
  • a genuine .git suffix is still stripped

Verified the new tests fail on the old code and pass with the fix; existing test suite (tests/test_code_indexer_output.py etc.) still passes.

str.rstrip() takes a set of characters, not a suffix, so
url.rstrip(".git") truncated any repository name ending in 'g', 'i',
't' or '.':

    https://github.com/facebook/react  -> https://github.com/facebook/reac
    https://github.com/foo/deep-learning -> .../deep-learnin

Both GitHubURLExtractor.extract_github_urls() and infer_repo_name() were
affected, so cloning a repo like facebook/react targeted a truncated,
non-existent (or wrong) repository URL/path.

Use removesuffix(".git") after stripping the trailing slash instead,
and add regression tests pinning the suffix-only behaviour.
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.

1 participant