| 1 | use crate::{prelude::*, routes::PageQuery}; |
| 2 | |
| 3 | pub struct Ref { |
| 4 | pub name: String, |
| 5 | pub is_head: bool, |
| 6 | } |
| 7 | |
| 8 | impl Ref { |
| 9 | pub fn resolve(repo: &Repository, query: &PageQuery) -> Result<Ref, Error> { |
| 10 | let head_branch_name = repo.head_branch_name()?; |
| 11 | match &query.head { |
| 12 | Some(h) if !h.is_empty() => Ok(Ref { |
| 13 | name: h.clone(), |
| 14 | is_head: *h == head_branch_name, |
| 15 | }), |
| 16 | _ => Ok(Ref { |
| 17 | name: head_branch_name, |
| 18 | is_head: true, |
| 19 | }), |
| 20 | } |
| 21 | } |
| 22 | } |
