From d46d9a22751ec21a6c39d1acf6b3f31a2b2eecd8 Mon Sep 17 00:00:00 2001 From: Can Celik Date: Wed, 12 Aug 2026 20:00:37 +0300 Subject: fix: preserve workspace labels for root repositories (#2727) refs #2594 --- src/app/git_refresh.rs | 42 ++++++++++++++++++++++++++++++++++++++++++ src/workspace.rs | 9 ++++++++- 2 files changed, 50 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/app/git_refresh.rs b/src/app/git_refresh.rs index 348b1556..c266add4 100644 --- a/src/app/git_refresh.rs +++ b/src/app/git_refresh.rs @@ -252,6 +252,48 @@ mod tests { let _ = std::fs::remove_dir_all(repo); } + #[test] + fn shared_root_repo_refresh_keeps_workspace_specific_fallback_labels() { + let cache_key = PathBuf::from("/"); + let cached = GitStatusCacheEntry { + fingerprint: None, + retry_after: Some(Instant::now() + std::time::Duration::from_secs(30)), + snapshot: crate::workspace::WorkspaceGitStatusSnapshot { + auto_label: "/".into(), + branch: Some("main".into()), + ahead_behind: None, + space: Some(crate::workspace::GitSpaceMetadata { + key: "/.git".into(), + checkout_key: "/".into(), + repo_name: "repo".into(), + repo_root: cache_key.clone(), + is_linked_worktree: false, + }), + }, + }; + let items = ["alpha", "beta"] + .into_iter() + .map(|name| WorkspaceGitRefreshItem { + workspace_id: name.into(), + resolved_identity_cwd: cache_key.join(name), + cache_key_hint: Some(cache_key.clone()), + }) + .collect(); + + let output = refresh_workspace_git_statuses_with_cache_and_demand( + items, + &HashMap::from([(cache_key, cached)]), + GitStatusRefreshDemand::ALL, + ); + + assert_eq!(output.cache_updates.len(), 1); + assert_eq!(output.results.len(), 2); + assert_eq!(output.results[0].auto_label, "alpha"); + assert_eq!(output.results[1].auto_label, "beta"); + assert_eq!(output.results[0].branch.as_deref(), Some("main")); + assert_eq!(output.results[1].branch.as_deref(), Some("main")); + } + #[test] fn git_refresh_item_collection_does_not_discover_uncached_cwd() { let mut app = test_app(&crate::config::Config::default()); diff --git a/src/workspace.rs b/src/workspace.rs index 85377f23..0a719ab1 100644 --- a/src/workspace.rs +++ b/src/workspace.rs @@ -83,12 +83,19 @@ impl WorkspaceGitStatusSnapshot { status_cache_key: PathBuf, demand: GitStatusRefreshDemand, ) -> WorkspaceGitStatus { + let auto_label = self + .space + .as_ref() + .map(|space| { + self::git::automatic_workspace_label(&resolved_identity_cwd, &space.repo_root) + }) + .unwrap_or_else(|| fallback_label_from_cwd(&resolved_identity_cwd)); WorkspaceGitStatus { workspace_id, resolved_identity_cwd, status_cache_key, demand, - auto_label: self.auto_label, + auto_label, branch: self.branch, ahead_behind: self.ahead_behind, space: self.space, -- cgit v1.2.3