Resolves the current branch name using `gix`. Falls back to `git symbolic-ref HEAD` for worktrees when gix cannot resolve HEAD (e.g. with minimal feature flags that exclude worktree support). Returns `None` for detached HEAD or if the repository cannot be opened.
(project_root: &Path)
| 10 | /// |
| 11 | /// Returns `None` for detached HEAD or if the repository cannot be opened. |
| 12 | pub fn current_branch(project_root: &Path) -> Option<String> { |
| 13 | match current_branch_gix(project_root) { |
| 14 | GixHead::Branch(branch) => Some(branch), |
| 15 | // A readable repo answered with a detached HEAD; `git symbolic-ref` |
| 16 | // would fail the same way, so don't spawn it. |
| 17 | GixHead::Detached => None, |
| 18 | GixHead::Unavailable => { |
| 19 | if !crate::worktree::git_may_resolve_repo(project_root) { |
| 20 | return None; |
| 21 | } |
| 22 | current_branch_git(project_root) |
| 23 | } |
| 24 | } |
| 25 | } |
| 26 | |
| 27 | /// Returns true if `branch` exists as a local `refs/heads/*` branch. |
| 28 | pub fn local_branch_exists(project_root: &Path, branch: &str) -> bool { |
no test coverage detected