From 6ccf156a3dd23f419c03892ddc1136e72957f66a Mon Sep 17 00:00:00 2001 From: Ogulcan Celik Date: Mon, 6 Apr 2026 22:05:00 +0300 Subject: refactor: use libghostty-native selection text reading --- src/workspace.rs | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) (limited to 'src/workspace.rs') diff --git a/src/workspace.rs b/src/workspace.rs index 25de6568..01a96b3f 100644 --- a/src/workspace.rs +++ b/src/workspace.rs @@ -670,13 +670,26 @@ pub fn derive_label_from_cwd(cwd: &Path) -> String { } pub fn git_branch(cwd: &Path) -> Option { - let repo_root = git_repo_root(cwd)?; - let head_path = repo_root.join(".git").join("HEAD"); - let content = std::fs::read_to_string(head_path).ok()?; - let trimmed = content.trim(); - trimmed - .strip_prefix("ref: refs/heads/") - .map(|s| s.to_string()) + git_repo_root(cwd)?; + + let output = std::process::Command::new("git") + .arg("-C") + .arg(cwd) + .args(["rev-parse", "--abbrev-ref", "HEAD"]) + .output() + .ok()?; + + if !output.status.success() { + return None; + } + + let stdout = String::from_utf8(output.stdout).ok()?; + let branch = stdout.trim(); + if branch.is_empty() || branch == "HEAD" { + None + } else { + Some(branch.to_string()) + } } fn git_repo_root(start: &Path) -> Option { -- cgit v1.2.3