From 9a5623a79523f5727c096870d98e2f8112d395ed Mon Sep 17 00:00:00 2001 From: NerdyPepper Date: Mon, 20 May 2019 18:35:32 +0530 Subject: fixed: status does not display in subdirectories --- src/vcs.rs | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/vcs.rs b/src/vcs.rs index db69897..eddc83c 100644 --- a/src/vcs.rs +++ b/src/vcs.rs @@ -1,15 +1,26 @@ use std::env; +use std::path::Path; use git2::{ Repository, Status }; use colored::*; pub fn vcs_status() -> Option<(colored::ColoredString, colored::ColoredString)> { let current_dir = env::var("PWD").unwrap(); - - let repo = match Repository::open(current_dir) { - Ok(r) => r, - Err(_) => return None - }; - + + let mut repo: Option = None; + let current_path = Path::new(¤t_dir[..]); + for path in current_path.ancestors() { + match Repository::open(path) { + Ok(r) => { + repo = Some(r); + break; + } + Err(_) => {}, + } + } + if repo.is_none() { + return None + } + let repo = repo.unwrap(); let reference = repo.head().unwrap(); let mut branch; -- cgit v1.2.3