diff options
| author | Ogulcan Celik <ogulcancelik@gmail.com> | 2026-04-06 22:05:00 +0300 |
|---|---|---|
| committer | Ogulcan Celik <ogulcancelik@gmail.com> | 2026-04-06 22:56:01 +0300 |
| commit | 6ccf156a3dd23f419c03892ddc1136e72957f66a (patch) | |
| tree | 1d5465e61d03344a63683ad3b9bbdec9a4476a5c /src/workspace.rs | |
| parent | 62b751b2b551d866e2aebfdecf89f7a003d64ebc (diff) | |
refactor: use libghostty-native selection text reading
Diffstat (limited to 'src/workspace.rs')
| -rw-r--r-- | src/workspace.rs | 27 |
1 files changed, 20 insertions, 7 deletions
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<String> { - 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<PathBuf> { |
