aboutsummaryrefslogtreecommitdiff
path: root/src/vcs.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/vcs.rs')
-rw-r--r--src/vcs.rs23
1 files changed, 17 insertions, 6 deletions
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 @@
1use std::env; 1use std::env;
2use std::path::Path;
2use git2::{ Repository, Status }; 3use git2::{ Repository, Status };
3use colored::*; 4use colored::*;
4 5
5pub fn vcs_status() -> Option<(colored::ColoredString, colored::ColoredString)> { 6pub fn vcs_status() -> Option<(colored::ColoredString, colored::ColoredString)> {
6 let current_dir = env::var("PWD").unwrap(); 7 let current_dir = env::var("PWD").unwrap();
7 8
8 let repo = match Repository::open(current_dir) { 9 let mut repo: Option<Repository> = None;
9 Ok(r) => r, 10 let current_path = Path::new(&current_dir[..]);
10 Err(_) => return None 11 for path in current_path.ancestors() {
11 }; 12 match Repository::open(path) {
12 13 Ok(r) => {
14 repo = Some(r);
15 break;
16 }
17 Err(_) => {},
18 }
19 }
20 if repo.is_none() {
21 return None
22 }
23 let repo = repo.unwrap();
13 let reference = repo.head().unwrap(); 24 let reference = repo.head().unwrap();
14 let mut branch; 25 let mut branch;
15 26