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{ pub enum GitRef{
Commit(String), Commit(String),
Branch(String), Branch(String),
Head,
} }
impl GitRef { impl GitRef {
@ -14,17 +15,14 @@ impl GitRef {
pub fn new_branch(s : String) -> GitRef { pub fn new_branch(s : String) -> GitRef {
GitRef::Branch(s) GitRef::Branch(s)
} }
fn value(&self) -> &String {
match self {
GitRef::Commit(s) => s,
GitRef::Branch(s) => s
}
}
} }
impl Display for GitRef { impl Display for GitRef {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { 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)?; let branch = self.git2.find_branch(branch.as_str(), BranchType::Local)?;
branch.get().peel_to_commit()? branch.get().peel_to_commit()?
} }
GitRef::Head => {
let head = self.git2.head()?;
head.peel_to_commit()?
}
}; };
let tree = commit.tree()?; let tree = commit.tree()?;
let fullname = PathBuf::from("/"); let fullname = PathBuf::from("/");

View File

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