Skip to content

Fix: prevent duplicate repositories in scan command#3

Closed
zhanba wants to merge 2 commits intomainfrom
fix-scan-duplication
Closed

Fix: prevent duplicate repositories in scan command#3
zhanba wants to merge 2 commits intomainfrom
fix-scan-duplication

Conversation

@zhanba
Copy link
Copy Markdown
Owner

@zhanba zhanba commented Nov 8, 2025

Summary

Fixes issue #2 where the pji 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).

Changes

  • Modified has_repo() method: Now compares repositories by hostname, user, repo name, and root directory instead of just the raw URI string
  • Updated remove_repo() method: Uses the same canonical comparison logic for consistency
  • Added unit test: Verifies that SSH and HTTPS URIs pointing to the same repository are correctly identified as duplicates
  • Improved error handling: Added proper error messages for repository operations (from previous fix)

Test plan

  • ✅ Unit test passes: test_has_repo_handles_different_uri_formats
  • ✅ Manual testing: Scan command no longer creates duplicates
  • ✅ All existing functionality remains intact
  • ✅ Handles edge cases like git worktrees (properly flagged as invalid)

Technical details

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:

Before: git@github.com:user/repo.githttps://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

zhanba and others added 2 commits November 8, 2025 17:44
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>
@zhanba zhanba requested a review from Copilot November 8, 2025 10:01
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@zhanba zhanba closed this Dec 4, 2025
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.

2 participants