Skip to content

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

fix: detect CI status when pushremote is a URL (#769)

Maximilian Roosc4f1c0730dcc
diff --git a/src/git/repository/branch.rs b/src/git/repository/branch.rs
index 773ff96cf..25aa2bab9 100644
--- a/src/git/repository/branch.rs
+++ b/src/git/repository/branch.rs
@@ -144,11 +144,30 @@ impl<'a> Branch<'a> {
/// Get the URL of the remote where this branch would be pushed.
///
- /// Combines [`push_remote()`](Self::push_remote) with remote URL lookup.
+ /// Uses `%(push:remotename)` which returns either a remote name or URL directly
+ /// (`gh pr checkout` sets pushremote to a URL rather than a remote name).
/// Returns `None` if no push remote is configured or the remote has no URL.
pub fn push_remote_url(&self) -> Option<String> {
- let remote = self.push_remote()?;
- self.repo.remote_url(&remote)
+ // %(push:remotename) returns either a remote name or URL directly
+ // Unlike @{push}, this doesn't fail when pushremote is a URL
+ let push_remote = self
+ .repo
+ .run_command(&[
+ "for-each-ref",
+ "--format=%(push:remotename)",
+ &format!("refs/heads/{}", self.name),
+ ])
+ .ok()
+ .map(|s| s.trim().to_string())
+ .filter(|s| !s.is_empty())?;
+
+ // If it's already a URL, return it directly
+ if push_remote.contains("://") || push_remote.starts_with("git@") {
+ Some(push_remote)
+ } else {
+ // It's a remote name, look up its URL
+ self.repo.remote_url(&push_remote)
+ }
}
/// Get the GitHub URL for this branch's push remote, if it's a GitHub URL.
diff --git a/tests/integration_tests/ci_status.rs b/tests/integration_tests/ci_status.rs
index 53cd03a45..022aff5e3 100644
--- a/tests/integration_tests/ci_status.rs
+++ b/tests/integration_tests/ci_status.rs
@@ -558,3 +558,57 @@ fn test_list_full_with_gitlab_filters_by_project_id(mut repo: TestRepo) {
Some(99999),
);
}
+
+// =============================================================================
+// URL-based pushremote tests (gh pr checkout scenario)
+// =============================================================================
+
+/// Test that CI status works when pushremote is a URL instead of a remote name.
+///
+/// This simulates the `gh pr checkout` scenario where git sets:
+/// - branch.<name>.pushremote = https://github.com/fork-owner/repo.git (a URL)
+/// - branch.<name>.merge = refs/pull/123/head (a PR ref)
+///
+/// Git's @{push} syntax fails with URLs, so we fall back to reading the config directly.
+#[rstest]
+fn test_list_full_with_url_based_pushremote(mut repo: TestRepo) {
+ // Set origin URL (the upstream repo where PRs are opened)
+ repo.run_git(&[
+ "remote",
+ "set-url",
+ "origin",
+ "https://github.com/upstream-owner/test-repo.git",
+ ]);
+ repo.add_worktree("feature");
+ let head_sha = get_branch_sha(&repo, "feature");
+
+ // Simulate `gh pr checkout` behavior:
+ // - Sets pushremote to the fork URL (not a remote name)
+ // - Sets merge to a PR ref (not a normal branch ref)
+ repo.run_git(&[
+ "config",
+ "branch.feature.pushremote",
+ "https://github.com/fork-owner/test-repo.git", // URL, not remote name
+ ]);
+ repo.run_git(&[
+ "config",
+ "branch.feature.merge",
+ "refs/pull/123/head", // PR ref, not branch ref
+ ]);
+
+ // The PR comes from the fork owner (matches pushremote URL)
+ let pr_json = format!(
+ r#"[{{
+ "headRefOid": "{}",
+ "mergeStateStatus": "CLEAN",
+ "statusCheckRollup": [
+ {{"status": "COMPLETED", "conclusion": "SUCCESS"}}
+ ],
+ "url": "https://github.com/upstream-owner/test-repo/pull/123",
+ "headRepositoryOwner": {{"login": "fork-owner"}}
+ }}]"#,
+ head_sha
+ );
+
+ run_ci_status_test(&mut repo, "url_based_pushremote", &pr_json, "[]");
+}
diff --git a/tests/snapshots/integration__integration_tests__ci_status__url_based_pushremote.snap b/tests/snapshots/integration__integration_tests__ci_status__url_based_pushremote.snap
new file mode 100644
index 000000000..d2d6bf64c
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__ci_status__url_based_pushremote.snap
@@ -0,0 +1,45 @@
+---
+source: tests/integration_tests/ci_status.rs
+info:
+ program: wt
+ args:
+ - list
+ - "--full"
+ env:
+ APPDATA: "[TEST_CONFIG_HOME]"
+ CLICOLOR_FORCE: "1"
+ COLUMNS: "500"
+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
+ GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"
+ GIT_CONFIG_SYSTEM: /dev/null
+ GIT_EDITOR: ""
+ GIT_TERMINAL_PROMPT: "0"
+ HOME: "[TEST_HOME]"
+ LANG: C
+ LC_ALL: C
+ MOCK_CONFIG_DIR: "[MOCK_CONFIG_DIR]"
+ PATH: "[PATH]"
+ RUST_LOG: warn
+ SHELL: ""
+ SOURCE_DATE_EPOCH: "1735776000"
+ TERM: alacritty
+ USERPROFILE: "[TEST_HOME]"
+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+ WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"
+ WT_TEST_DELAYED_STREAM_MS: "-1"
+ XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"
+---
+success: true
+exit_code: 0
+----- stdout -----
+ Branch Status HEAD± main↕ main…± Path Remote⇅ CI Commit Age Message
+@ main ^| . | 05a4a45d 16h Initial commit
++ feature _ ../repo.feature ● 05a4a45d 16h Initial commit
++ feature-a ↑ ↑1 +1 ../repo.feature-a 1b87d473 16h Add feature-a file
++ feature-b ↑ ↑1 +1 ../repo.feature-b f62940fc 16h Add feature-b file
++ feature-c ↑ ↑1 +1 ../repo.feature-c 345c7c93 16h Add feature-c file
+
+○ Showing 5 worktrees, 3 ahead
+
+----- stderr -----