Skip to content

Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows

fix: check GitLab MR remote in branch_tracks_ref (#1817)

Maximilian Roos2b4abc8f82de
diff --git a/src/commands/worktree/switch.rs b/src/commands/worktree/switch.rs
index 754505adb..de08a7b51 100644
--- a/src/commands/worktree/switch.rs
+++ b/src/commands/worktree/switch.rs
@@ -116,7 +116,13 @@ fn resolve_fork_ref(
None
}
},
- RefType::Mr => None,
+ RefType::Mr => match find_gitlab_remote(repo, info) {
+ Ok(remote) => Some(remote),
+ Err(e) => {
+ log::debug!("Could not resolve GitLab remote for MR: {e:#}");
+ None
+ }
+ },
};
// Check if branch already exists and is tracking this ref
@@ -284,6 +290,31 @@ fn find_github_remote(repo: &Repository, info: &RemoteRefInfo) -> anyhow::Result
})
}
+/// Find the remote for a GitLab MR (where MR refs live).
+fn find_gitlab_remote(repo: &Repository, info: &RemoteRefInfo) -> anyhow::Result<String> {
+ use worktrunk::git::remote_ref::PlatformData;
+
+ let PlatformData::GitLab {
+ host,
+ base_owner,
+ base_repo,
+ ..
+ } = &info.platform_data
+ else {
+ anyhow::bail!("find_gitlab_remote called on non-GitLab ref");
+ };
+
+ repo.find_remote_for_repo(Some(host), base_owner, base_repo)
+ .ok_or_else(|| {
+ GitError::NoRemoteForRepo {
+ owner: base_owner.clone(),
+ repo: base_repo.clone(),
+ suggested_url: format!("https://{host}/{base_owner}/{base_repo}.git"),
+ }
+ .into()
+ })
+}
+
/// Resolve a same-repo (non-fork) PR/MR.
fn resolve_same_repo_ref(
repo: &Repository,