Skip to content

Commit 44b61be

Browse files
max-sixtyclaude
andauthored
refactor(git): consolidate PR/MR resolution into unified remote_ref module (#893)
* refactor(git): consolidate PR/MR resolution into unified remote_ref module Replace duplicate pr_ref.rs (520 lines) and mr_ref.rs (715 lines) with a trait-based architecture in remote_ref/. Both platforms now share: - RemoteRefProvider trait defining the platform-agnostic interface - RemoteRefInfo struct with platform-specific data in PlatformData enum - Unified resolve_remote_ref() in switch.rs Also: - Add ref_path field to CreationMethod::ForkRef to avoid re-deriving - Add -- separators to git fetch/worktree commands for security - Update module docs to reflect current API Net reduction: ~420 lines. Adding new platforms (e.g., Bitbucket) now requires only implementing RemoteRefProvider. Co-Authored-By: Claude <noreply@anthropic.com> * fix(gitlab): defer project URL fetching for ~1s perf improvement GitLab fork MRs required 2 API calls (~500ms each) to fetch source and target project URLs. These calls happened unconditionally, even when the branch already tracked the MR (common case when re-switching). Now: - fetch_mr_info only fetches MR metadata (no project URL calls) - fetch_gitlab_project_urls is called only after branch_tracks_ref fails - For branches already configured, we skip ~1 second of API calls Also fixes nested namespace display in source_ref output: - extract_namespace_from_url now handles group/subgroup/repo correctly - Example: git@gitlab.com:org/team/repo.git → org/team Trade-off: Fork MR display now shows branch name only (not namespace:branch) since fork_push_url isn't available until after the deferred fetch. The full URL is still shown, and this only affects display, not functionality. Co-Authored-By: Claude <noreply@anthropic.com> * docs(gitlab): explain deferred URL fetching vs GitHub Document why GitLab requires separate API calls for project URLs while GitHub returns everything in one call. This explains the optimization that defers URL fetching until after branch_tracks_ref check. Co-Authored-By: Claude <noreply@anthropic.com> * test(gitlab): add test for fetch_gitlab_project_urls validation Cover the defensive check that rejects non-GitLab refs. Co-Authored-By: Claude <noreply@anthropic.com> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent a567d5d commit 44b61be

File tree

11 files changed

+1260
-1597
lines changed

11 files changed

+1260
-1597
lines changed

src/commands/worktree/switch.rs

Lines changed: 229 additions & 245 deletions
Large diffs are not rendered by default.

src/commands/worktree/types.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ pub enum CreationMethod {
7575
ref_type: RefType,
7676
/// The PR/MR number.
7777
number: u32,
78+
/// The ref path (e.g., "pull/123/head" or "merge-requests/42/head").
79+
ref_path: String,
7880
/// URL to push to (the fork's URL). `None` when using a prefixed branch
7981
/// name (e.g., `contributor/main`) because push won't work.
8082
fork_push_url: Option<String>,

src/git/mod.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@ use std::path::PathBuf;
55
// Submodules
66
mod diff;
77
mod error;
8-
pub mod mr_ref;
98
mod parse;
10-
pub mod pr_ref;
119
pub mod remote_ref;
1210
mod repository;
1311
mod url;

0 commit comments

Comments
 (0)