fix(tools): stop rstrip(".git") from mangling repository names - #174
Open
hobostay wants to merge 1 commit into
Open
fix(tools): stop rstrip(".git") from mangling repository names#174hobostay wants to merge 1 commit into
hobostay wants to merge 1 commit into
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
GitHubURLExtractorintools/git_command.pynormalizes URLs withurl.rstrip(".git")(two call sites:extract_github_urls()andinfer_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: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), andinfer_repo_name()derives a wrong target directory name.Fix
Strip the trailing slash first, then remove only the real suffix:
(removesuffix requires Python 3.9+; the project requires >= 3.12.)
Tests
Added
tests/test_git_command_url.pywith regression tests covering:t/g/... are preserved (facebook/react,deep-learning).gitsuffix is still strippedVerified the new tests fail on the old code and pass with the fix; existing test suite (
tests/test_code_indexer_output.pyetc.) still passes.