This commit is contained in:
Hubert 2021-07-18 14:40:56 +02:00
parent 82757ef9eb
commit aa656d3a19
3 changed files with 11 additions and 9 deletions

View File

@ -4,6 +4,7 @@ use std::fmt::{Display, Formatter};
pub enum GitRef{
Commit(String),
Branch(String),
Head,
}
impl GitRef {
@ -14,17 +15,14 @@ impl GitRef {
pub fn new_branch(s : String) -> GitRef {
GitRef::Branch(s)
}
fn value(&self) -> &String {
match self {
GitRef::Commit(s) => s,
GitRef::Branch(s) => s
}
}
}
impl Display for GitRef {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.value())
write!(f, "{}", match &self {
GitRef::Commit(s) => {s.as_str()}
GitRef::Branch(s) => {s.as_str()}
GitRef::Head => {"HEAD"}
})
}
}

View File

@ -30,6 +30,10 @@ impl GitRepo {
let branch = self.git2.find_branch(branch.as_str(), BranchType::Local)?;
branch.get().peel_to_commit()?
}
GitRef::Head => {
let head = self.git2.head()?;
head.peel_to_commit()?
}
};
let tree = commit.tree()?;
let fullname = PathBuf::from("/");

View File

@ -158,7 +158,7 @@ async fn git_main(
};
let commit = match commitnameopt {
None => {match branchopt {
None => {GitRef::Branch("master".to_string())}
None => {GitRef::Head}
Some(s) => {GitRef::Branch(s)}
}}
Some(s) => {GitRef::Commit(s)}