Fix: prevent duplicate repositories in scan command#3
Closed
Conversation
Previously, running `pji open`, `pji open pr`, or `pji open issue` commands outside of a managed repository would cause the application to panic with an unwelcome error message. This fix: - Replaces `.expect()` calls with proper error handling using match statements - Provides user-friendly error messages when no repository is found - Improves path resolution by canonicalizing both current and repository paths - Adds a new `error_message()` helper method for consistent error formatting The commands now gracefully handle cases where users run them from directories not managed by pji, improving the overall user experience. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Fixes issue #2 where the scan command would create duplicate entries when the same repository was discovered with different URI formats (e.g., SSH vs HTTPS URLs pointing to the same repo). The problem was in the has_repo() and remove_repo() methods which only compared the raw URI string instead of the repository's canonical identity. Changes: - Modified has_repo() to compare repositories by hostname, user, repo name, and root - Updated remove_repo() to use the same comparison logic for consistency - Added unit test to verify the fix handles different URI formats correctly - Scan now correctly identifies duplicates regardless of URI format This ensures that git@github.com:user/repo.git and https://github.com/user/repo.git are recognized as the same repository and prevents duplicate entries. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
There was a problem hiding this comment.
Pull Request Overview
This pull request improves repository matching to be protocol-agnostic (SSH vs HTTPS) and enhances error handling for repository operations.
- Changed repository comparison logic to match based on hostname, user, repo, and root instead of the full URI string
- Replaced
expect()panic calls with graceful error handling and user-friendly error messages - Added path canonicalization to improve repository detection with symlinks
- Added comprehensive test coverage for the new protocol-agnostic matching behavior
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/config.rs | Updated remove_repo and has_repo to compare repositories by hostname/user/repo/root instead of full URI, enabling protocol-agnostic matching; added test to verify SSH and HTTPS URIs are treated as the same repository |
| src/app.rs | Replaced panic-inducing expect() calls with graceful error handling in open_home, open_pr, and open_issue; added path canonicalization in get_cwd_repo for better symlink handling; added error_message helper function for consistent error reporting |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
Summary
Fixes issue #2 where the
pji scancommand would create duplicate entries when the same repository was discovered with different URI formats (e.g., SSH vs HTTPS URLs pointing to the same repo).Changes
has_repo()method: Now compares repositories by hostname, user, repo name, and root directory instead of just the raw URI stringremove_repo()method: Uses the same canonical comparison logic for consistencyTest plan
test_has_repo_handles_different_uri_formatsTechnical details
The problem was in the
has_repo()andremove_repo()methods which only compared the raw URI string instead of the repository's canonical identity:Before:
git@github.com:user/repo.git≠https://github.com/user/repo.git(different repos)After: Same canonical identity (github.com/user/repo) = same repository
This ensures repositories are identified by their canonical identity rather than URI format, preventing duplicates while maintaining all existing functionality.
🤖 Generated with Claude Code