Skip to content

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

perf(repo): resolve is_remote_tracking_branch via cached inventory (#2377)

Maximilian Roosf808ed3818bf
diff --git a/src/git/repository/remotes.rs b/src/git/repository/remotes.rs
index 782c9db90..658197024 100644
--- a/src/git/repository/remotes.rs
+++ b/src/git/repository/remotes.rs
@@ -315,15 +315,17 @@ impl Repository {
/// Check if a ref is a remote tracking branch.
///
- /// Returns true if the ref exists under `refs/remotes/` (e.g., `origin/main`).
- /// Returns false for local branches, tags, SHAs, and non-existent refs.
+ /// Returns true if the ref appears in the remote-branch inventory
+ /// (e.g., `origin/main`). Returns false for local branches, tags, SHAs,
+ /// non-existent refs, and `<remote>/HEAD` symrefs (which the inventory
+ /// excludes).
+ ///
+ /// Resolved from the remote-branch inventory — no subprocess calls once
+ /// it's populated.
pub fn is_remote_tracking_branch(&self, ref_name: &str) -> bool {
- self.run_command(&[
- "rev-parse",
- "--verify",
- &format!("refs/remotes/{}", ref_name),
- ])
- .is_ok()
+ self.remote_branches()
+ .ok()
+ .is_some_and(|branches| branches.iter().any(|r| r.short_name == ref_name))
}
/// Strip the remote prefix from a remote-tracking branch name.