MCPcopy Create free account
hub / github.com/ScriptedAlchemy/tracedecay / current_branch

Function current_branch

src/branch.rs:12–25  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

10///
11/// Returns `None` for detached HEAD or if the repository cannot be opened.
12pub 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.
28pub fn local_branch_exists(project_root: &Path, branch: &str) -> bool {

Callers 15

handle_branch_actionFunction · 0.85
notify_hook_eventFunction · 0.85
branch_driftedMethod · 0.85
init_with_optionsMethod · 0.85
open_with_optionsMethod · 0.85

Calls 3

current_branch_gixFunction · 0.85
git_may_resolve_repoFunction · 0.85
current_branch_gitFunction · 0.85

Tested by

no test coverage detected