diff options
Diffstat (limited to 'src/vcs.rs')
-rw-r--r-- | src/vcs.rs | 23 |
1 files changed, 17 insertions, 6 deletions
@@ -1,15 +1,26 @@ | |||
1 | use std::env; | 1 | use std::env; |
2 | use std::path::Path; | ||
2 | use git2::{ Repository, Status }; | 3 | use git2::{ Repository, Status }; |
3 | use colored::*; | 4 | use colored::*; |
4 | 5 | ||
5 | pub fn vcs_status() -> Option<(colored::ColoredString, colored::ColoredString)> { | 6 | pub 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(¤t_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 | ||