fix status crash with empty head repo

master
Aleš Katona 2 years ago
parent 2ea821461f
commit 9f4919e9af
Signed by: almindor
GPG Key ID: 2F773149BF38B48F

@ -67,9 +67,25 @@ impl Project {
&self.path &self.path
} }
pub fn current_ref(&self) -> Result<Option<String>, Error> {
match self.repo.current_ref() {
Ok(val) => Ok(Some(val)),
Err(err) => {
eprintln!("{}: {}\n", self.name(), err);
Ok(None)
}
}
}
pub fn current_profile(&self) -> Result<Option<String>, Error> { pub fn current_profile(&self) -> Result<Option<String>, Error> {
let current_ref = self.repo.current_ref()?; // repo.current_ref can fail if repo has no head yet (e.g. post init)
if let Some(val) = self.profile_map.iter().find(|v| v.1 == &current_ref) { let current_ref = self.current_ref()?;
if let Some(val) = self
.profile_map
.iter()
.find(|v| Some(v.1) == current_ref.as_ref())
{
return Ok(Some(val.0.clone())); return Ok(Some(val.0.clone()));
} }
@ -127,7 +143,9 @@ impl Project {
let title = format!( let title = format!(
"{}: {} [{}]", "{}: {} [{}]",
self.name().bold().with(PROJECT_COLOR), self.name().bold().with(PROJECT_COLOR),
self.repo.current_ref()?.with(REFS_COLOR), self.current_ref()?
.unwrap_or_else(|| "???".into())
.with(REFS_COLOR),
format!("{}", self.path().display()).italic(), format!("{}", self.path().display()).italic(),
); );
let mut root = Tree::new(title); let mut root = Tree::new(title);

Loading…
Cancel
Save