verify_branch

Function verify_branch 

Source
pub fn verify_branch(branch: &str, dir: &Path) -> bool
Expand description

Verify that a branch exists locally in the given repository.

Internally runs:

git rev-parse --verify <branch>

This is a thin wrapper around get_git_output, returning true if the Git call succeeds and false otherwise.

§Arguments

  • branch — The name of the branch to check.
  • dir — Path to the Git repository root or working directory.

§Returns

  • true if the branch exists locally.
  • false otherwise.

§Example

use std::path::Path;
use mdbook_gitinfo::git::verify_branch;

let dir = Path::new(".");
if !verify_branch("dev", dir) {
    eprintln!("Branch 'dev' not found, falling back to 'main'");
}