diff --git a/src/vcs/project.rs b/src/vcs/project.rs index e0b990d..27c6fd0 100644 --- a/src/vcs/project.rs +++ b/src/vcs/project.rs @@ -67,9 +67,25 @@ impl Project { &self.path } + pub fn current_ref(&self) -> Result, 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, Error> { - let current_ref = self.repo.current_ref()?; - if let Some(val) = self.profile_map.iter().find(|v| v.1 == ¤t_ref) { + // repo.current_ref can fail if repo has no head yet (e.g. post init) + 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())); } @@ -127,7 +143,9 @@ impl Project { let title = format!( "{}: {} [{}]", 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(), ); let mut root = Tree::new(title);