index : gitrs
A lightweight web interface for browsing Git repositories, implemented in Rust
about summary refs log tree commit diff

Diffstat (limited to 'src/git/refs.rs')

-rw-r--r-- src/git/refs.rs 22
 1 file changed, 22 insertions(+)

diff --git a/src/git/refs.rs b/src/git/refs.rs
new file mode 100644
index 0000000..8a2ef7a 100644
--- /dev/null
+++ b/src/git/refs.rs
@@ -1,0 +1,22 @@
use crate::{prelude::*, routes::PageQuery};

pub struct Ref {
    pub name: String,
    pub is_head: bool,
}

impl Ref {
    pub fn resolve(repo: &Repository, query: &PageQuery) -> Result<Ref, Error> {
        let head_branch_name = repo.head_branch_name()?;
        match &query.head {
            Some(h) if !h.is_empty() => Ok(Ref {
                name: h.clone(),
                is_head: *h == head_branch_name,
            }),
            _ => Ok(Ref {
                name: head_branch_name,
                is_head: true,
            }),
        }
    }
}