diff options
author | NerdyPepper <[email protected]> | 2019-05-20 14:05:32 +0100 |
---|---|---|
committer | NerdyPepper <[email protected]> | 2019-05-20 14:05:32 +0100 |
commit | 9a5623a79523f5727c096870d98e2f8112d395ed (patch) | |
tree | bad8c7843285736698df9f8b98730d443a9f6c9c /src/vcs.rs | |
parent | f982aa673701bd5084a228ce9caee6941e3d86f1 (diff) |
fixed: status does not display in subdirectories
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 | ||