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.rsindex 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.rsindex 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.snapnew file mode 100644index 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 -----+ [1mBranch[0m [1mStatus[0m [1mHEAD±[0m [1mmain↕[0m [1mmain…±[0m [1mPath[0m [1mRemote⇅[0m [1mCI[0m [1mCommit[0m [1mAge[0m [1mMessage+@ main [2m^[22m[2m|[22m . [2m|[0m [2m05a4a45d[0m [2m16h[0m [2mInitial commit++ [2mfeature[0m [2m_[22m [2m../repo.feature[0m [32m●[0m [2m05a4a45d[0m [2m16h[0m [2mInitial commit++ feature-a [2m↑[22m [32m↑1[0m [32m+1[0m ../repo.feature-a [2m1b87d473[0m [2m16h[0m [2mAdd feature-a file++ feature-b [2m↑[22m [32m↑1[0m [32m+1[0m ../repo.feature-b [2mf62940fc[0m [2m16h[0m [2mAdd feature-b file++ feature-c [2m↑[22m [32m↑1[0m [32m+1[0m ../repo.feature-c [2m345c7c93[0m [2m16h[0m [2mAdd feature-c file++[2m○[22m [2mShowing 5 worktrees, 3 ahead++----- stderr -----