mirror of
https://forge.pointfixe.fr/hubert/gitust.git
synced 2026-02-04 15:57:30 +01:00
head
This commit is contained in:
@@ -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"}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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("/");
|
||||||
|
|||||||
@@ -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)}
|
||||||
|
|||||||
Reference in New Issue
Block a user