Skip to content

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

fix(list): treat [gone] upstream as no upstream (#2262)

Maximilian Roos256115afbff5
diff --git a/src/git/repository/branches.rs b/src/git/repository/branches.rs
index 46ff56e55..68e07be30 100644
--- a/src/git/repository/branches.rs
+++ b/src/git/repository/branches.rs
@@ -119,20 +119,25 @@ impl Repository {
/// Fetch all upstream tracking branches in a single `git for-each-ref` call.
///
/// Returns a map from local branch name to upstream ref (or None if no
- /// upstream is configured). Called lazily via `OnceCell` on first
+ /// upstream is configured, or if the configured upstream ref no longer
+ /// exists on the remote — git reports that as `[gone]` via
+ /// `%(upstream:track)`). Called lazily via `OnceCell` on first
/// `Branch::upstream()` access.
pub(super) fn fetch_all_upstreams(&self) -> anyhow::Result<HashMap<String, Option<String>>> {
let output = self.run_command(&[
"for-each-ref",
- "--format=%(refname:lstrip=2)\t%(upstream:short)",
+ "--format=%(refname:lstrip=2)\t%(upstream:short)\t%(upstream:track)",
"refs/heads/",
])?;
Ok(output
.lines()
.filter_map(|line| {
- let (branch, upstream) = line.split_once('\t')?;
- let value = if upstream.is_empty() {
+ let mut parts = line.splitn(3, '\t');
+ let branch = parts.next()?;
+ let upstream = parts.next()?;
+ let track = parts.next()?;
+ let value = if upstream.is_empty() || track == "[gone]" {
None
} else {
Some(upstream.to_string())
diff --git a/tests/integration_tests/list.rs b/tests/integration_tests/list.rs
index 230984a70..7d05ac2d6 100644
--- a/tests/integration_tests/list.rs
+++ b/tests/integration_tests/list.rs
@@ -565,6 +565,13 @@ fn test_list_with_upstream_tracking(mut repo: TestRepo) {
// isn't ready when wt list tries to read commit timestamps.
repo.run_git_in(&no_upstream_wt, &["status", "--porcelain"]);
+ // Scenario 6: Upstream configured but remote ref deleted (git's [gone] state).
+ // Should be treated as no upstream — blank Remote column, no error.
+ let gone_wt = repo.add_worktree("gone-upstream");
+ repo.run_git_in(&gone_wt, &["push", "-u", "origin", "gone-upstream"]);
+ repo.run_git(&["push", "origin", "--delete", "gone-upstream"]);
+ repo.run_git_in(&gone_wt, &["fetch", "--prune", "origin"]);
+
// Run list --branches --full to show all columns including Remote
assert_cmd_snapshot!("with_upstream_tracking", {
let mut cmd = wt_command();
diff --git a/tests/snapshots/integration__integration_tests__list__with_upstream_tracking.snap b/tests/snapshots/integration__integration_tests__list__with_upstream_tracking.snap
index 9565e5683..14c907ec1 100644
--- a/tests/snapshots/integration__integration_tests__list__with_upstream_tracking.snap
+++ b/tests/snapshots/integration__integration_tests__list__with_upstream_tracking.snap
@@ -43,17 +43,18 @@ info:
success: true
exit_code: 0
----- stdout -----
- Branch Status HEAD± main↕ main…± Remote⇅ CI Path Commit Age Message
-@ main ^⇡ ⇡1 . 01cab36c 1d Initial commit on main
-+ feature-a ↕ ↑1 ↓1 +1 ../repo.feature-a 1b87d473 16h Add feature-a file
-+ feature-b ↕ ↑1 ↓1 +1 ../repo.feature-b f62940fc 16h Add feature-b file
-+ feature-c ↕ ↑1 ↓1 +1 ../repo.feature-c 345c7c93 16h Add feature-c file
-+ ahead ↑⇡ ↑2 +2 ⇡2 ../repo.ahead a25eff2a 1d Ahead commit 2
-+ behind _⇣ ⇣1 ../repo.behind 01cab36c 1d Initial commit on main
-+ diverged ↑⇅ ↑1 +1 ⇡1 ⇣1 ../repo.diverged f035d2c5 1d Diverged local commit
-+ in-sync _| | ../repo.in-sync 01cab36c 1d Initial commit on main
-+ no-upstream _ ../repo.no-upstream 01cab36c 1d Initial commit on main
+ Branch Status HEAD± main↕ main…± Remote⇅ CI Path Commit Age Message
+@ main ^⇡ ⇡1 . 01cab36c 1d Initial commit on main
++ feature-a ↕ ↑1 ↓1 +1 ../repo.feature-a 1b87d473 16h Add feature-a file
++ feature-b ↕ ↑1 ↓1 +1 ../repo.feature-b f62940fc 16h Add feature-b file
++ feature-c ↕ ↑1 ↓1 +1 ../repo.feature-c 345c7c93 16h Add feature-c file
++ ahead ↑⇡ ↑2 +2 ⇡2 ../repo.ahead a25eff2a 1d Ahead commit 2
++ behind _⇣ ⇣1 ../repo.behind 01cab36c 1d Initial commit on main
++ diverged ↑⇅ ↑1 +1 ⇡1 ⇣1 ../repo.diverged f035d2c5 1d Diverged local commit
++ gone-upstream _ ../repo.gone-upstream 01cab36c 1d Initial commit on main
++ in-sync _| | ../repo.in-sync 01cab36c 1d Initial commit on main
++ no-upstream _ ../repo.no-upstream 01cab36c 1d Initial commit on main
-○ Showing 9 worktrees, 5 ahead
+○ Showing 10 worktrees, 5 ahead
----- stderr -----