Crate gitbrowse[][src]

A crate to browse a git repository in a way that most people are used to. Heavily inspired by how people browse a git repository on github and gitlab.


let repo = Repo::open(".")?;

let branches = repo.list_branches()?;
println!("Found the following branches:");
for branch in &branches {
    println!(" - {}", branch);
}

let current_branch = match repo.current_branch()? {
    Some(b) => b,
    None => return Ok(())
};
println!("Current branch: {:?}", current_branch.name());

current_branch.files(|file| {
    println!("Found file: {:?}", file.path());
    if let Ok(content) = file.read_content_string() {
        println!("File's content is length {}", content.len());
    }
     
    println!("File is modified in the following commits:");
    for commit in file.history()? {
        if let Ok(commit) = commit {
            println!("  {}: {}", commit.id(), commit.message());
        }
    }
    Ok(())
})?;

Structs

Branch

A reference to a branch on the git repo.

Commit

A reference to a commit in the repository.

Error

A structure to represent errors coming out of libgit2.

File

A reference to a file on a certain commit.

NameWithId
Repo

A reference to an opened repository.