Skip to content

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

Pass has_upstream to PrStatus::detect for workflow fallback

Maximilian Roosbad440ec70ab
diff --git a/src/commands/config.rs b/src/commands/config.rs
index eb1bb2226..99fe87602 100644
--- a/src/commands/config.rs
+++ b/src/commands/config.rs
@@ -544,7 +544,8 @@ pub fn handle_var_get(key: &str, refresh: bool, branch: Option<String>) -> anyho
let _ = repo.run_command(&["config", "--unset", &config_key]);
}
- match PrStatus::detect(&branch_name, &head, &repo_root) {
+ let has_upstream = repo.upstream_branch(&branch_name).ok().flatten().is_some();
+ match PrStatus::detect(&branch_name, &head, &repo_root, has_upstream) {
Some(status) => {
// Output the CI status as a simple string for piping
let status_str = match status.ci_status {
diff --git a/src/commands/list/ci_status.rs b/src/commands/list/ci_status.rs
index a62b1c722..8361470f1 100644
--- a/src/commands/list/ci_status.rs
+++ b/src/commands/list/ci_status.rs
@@ -549,7 +549,14 @@ impl PrStatus {
///
/// # Arguments
/// * `repo_path` - Repository root path from `Repository::worktree_root()`
- pub fn detect(branch: &str, local_head: &str, repo_path: &std::path::Path) -> Option<Self> {
+ /// * `has_upstream` - Whether the branch has upstream tracking configured.
+ /// PR/MR detection always runs. Workflow/pipeline fallback only runs if true.
+ pub fn detect(
+ branch: &str,
+ local_head: &str,
+ repo_path: &std::path::Path,
+ has_upstream: bool,
+ ) -> Option<Self> {
// We run gh/glab commands from the repo directory to let them auto-detect the correct repo
// (including upstream repos for forks)
let repo_root = repo_path.to_str()?;
@@ -579,7 +586,7 @@ impl PrStatus {
}
// Cache miss or expired - fetch fresh status
- let status = Self::detect_uncached(branch, local_head, repo_root);
+ let status = Self::detect_uncached(branch, local_head, repo_root, has_upstream);
// Cache the result (including None - means no CI found for this branch)
let cached = CachedCiStatus {
@@ -593,19 +600,33 @@ impl PrStatus {
}
/// Detect CI status without caching (internal implementation)
- fn detect_uncached(branch: &str, local_head: &str, repo_root: &str) -> Option<Self> {
- // Try GitHub PR first
+ ///
+ /// PR/MR detection always runs. Workflow/pipeline fallback only runs if `has_upstream`.
+ fn detect_uncached(
+ branch: &str,
+ local_head: &str,
+ repo_root: &str,
+ has_upstream: bool,
+ ) -> Option<Self> {
+ // Try GitHub PR first (always, regardless of upstream)
if let Some(status) = Self::detect_github(branch, local_head, repo_root) {
return Some(status);
}
- // Try GitHub workflow runs (for branches without PRs)
- if let Some(status) = Self::detect_github_workflow(branch, local_head, repo_root) {
+ // Try GitLab MR (always, regardless of upstream)
+ if let Some(status) = Self::detect_gitlab(branch, local_head, repo_root) {
return Some(status);
}
- // Try GitLab MR
- if let Some(status) = Self::detect_gitlab(branch, local_head, repo_root) {
+ // Workflow/pipeline fallback only if upstream is configured.
+ // This prevents false matches from similarly-named branches on the remote
+ // that aren't actually related to the local branch.
+ if !has_upstream {
+ return None;
+ }
+
+ // Try GitHub workflow runs (for branches without PRs)
+ if let Some(status) = Self::detect_github_workflow(branch, local_head, repo_root) {
return Some(status);
}
diff --git a/src/commands/list/collect_progressive_impl.rs b/src/commands/list/collect_progressive_impl.rs
index d765a8f50..c9540f198 100644
--- a/src/commands/list/collect_progressive_impl.rs
+++ b/src/commands/list/collect_progressive_impl.rs
@@ -499,9 +499,9 @@ impl Task for UpstreamTask {
/// Task 10: CI/PR status
///
-/// Only checks CI for branches that have an upstream tracking branch configured.
-/// This prevents false matches from similarly-named branches on the remote that
-/// aren't actually related to the local branch.
+/// Always checks for open PRs/MRs regardless of upstream tracking.
+/// For branch workflow/pipeline fallback (no PR), requires upstream tracking
+/// to prevent false matches from similarly-named branches on the remote.
pub struct CiStatusTask;
impl Task for CiStatusTask {
@@ -515,11 +515,8 @@ impl Task for CiStatusTask {
.unwrap_or_else(|| ctx.repo_path.clone());
let pr_status = ctx.branch.as_deref().and_then(|branch| {
- // Only check CI for branches with an upstream configured.
- // This prevents showing CI for old branches that happen to have
- // same-named branches on the remote but aren't tracking them.
- repo.upstream_branch(branch).ok().flatten()?;
- PrStatus::detect(branch, &ctx.commit_sha, &repo_path)
+ let has_upstream = repo.upstream_branch(branch).ok().flatten().is_some();
+ PrStatus::detect(branch, &ctx.commit_sha, &repo_path, has_upstream)
});
TaskResult::CiStatus {