From 55fb57c025481f3cc7ab48af4b2065126016768d Mon Sep 17 00:00:00 2001 From: Ninan John Date: Wed, 25 Dec 2019 10:13:26 +0530 Subject: [PATCH 1/2] [Ninan] Handle directories that do not have remote HEAD's --- src/status.rs | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/src/status.rs b/src/status.rs index 3929100..01ad571 100644 --- a/src/status.rs +++ b/src/status.rs @@ -96,22 +96,24 @@ impl<'a> GitAction for GitStatus<'a> { }; // Adapted from @Kurt-Bonatz in https://github.com/rust-lang/git2-rs/issues/332#issuecomment-408453956 - let head_ref = self.repo.revparse_single("HEAD").unwrap().id(); - let (is_ahead, is_behind) = self.repo.revparse_ext("@{u}") - .ok() - .and_then(|(upstream, _)| self.repo.graph_ahead_behind(head_ref, upstream.id()).ok()) - .unwrap_or((0, 0)); + if self.repo.revparse_single("HEAD").is_ok() { + let head_ref = self.repo.revparse_single("HEAD").expect("HEAD not found").id(); + let (is_ahead, is_behind) = self.repo.revparse_ext("@{u}") + .ok() + .and_then(|(upstream, _)| self.repo.graph_ahead_behind(head_ref, upstream.id()).ok()) + .unwrap_or((0, 0)); - if is_ahead > 0 { - let push_string = format!("{} ahead", is_ahead); - let push_string_colored = format!("{}", push_string.blue()); - statuses_in_dir.push(push_string_colored); - } + if is_ahead > 0 { + let push_string = format!("{} ahead", is_ahead); + let push_string_colored = format!("{}", push_string.blue()); + statuses_in_dir.push(push_string_colored); + } - if is_behind > 0 { - let push_string = format!("{} behind", is_ahead); - let push_string_colored = format!("{}", push_string.yellow()); - statuses_in_dir.push(push_string_colored); + if is_behind > 0 { + let push_string = format!("{} behind", is_ahead); + let push_string_colored = format!("{}", push_string.yellow()); + statuses_in_dir.push(push_string_colored); + } } if statuses_in_dir.is_empty() { From 30398cd35df2372f415171a37ca79712c767b807 Mon Sep 17 00:00:00 2001 From: Ninan John Date: Wed, 25 Dec 2019 10:14:43 +0530 Subject: [PATCH 2/2] [Ninan] Fix bug where status shows wrong number of commits behind --- src/status.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/status.rs b/src/status.rs index 01ad571..fb6b7e1 100644 --- a/src/status.rs +++ b/src/status.rs @@ -110,9 +110,9 @@ impl<'a> GitAction for GitStatus<'a> { } if is_behind > 0 { - let push_string = format!("{} behind", is_ahead); - let push_string_colored = format!("{}", push_string.yellow()); - statuses_in_dir.push(push_string_colored); + let pull_string = format!("{} behind", is_behind); + let pull_string_colored = format!("{}", pull_string.yellow()); + statuses_in_dir.push(pull_string_colored); } }