Move current_branch() into prompt module for now

Since this appears to be the only user, it seems sensible to keep it close
to the related code for the time being. If broader Git functionality is
needed in other places, it can always be extracted again.
This commit is contained in:
Dirkjan Ochtman 2019-08-26 20:06:56 +02:00
parent 9033bc38bb
commit 0c3c24104d
3 changed files with 20 additions and 23 deletions

View File

@ -1,21 +0,0 @@
use git2::{Repository, RepositoryOpenFlags};
use std::ffi::OsString;
pub fn current_branch() -> Option<String> {
let v: Vec<OsString> = vec![];
match Repository::open_ext(".", RepositoryOpenFlags::empty(), v) {
Ok(repo) => {
let r = repo.head();
match r {
Ok(r) => {
match r.shorthand() {
Some(s) => Some(s.to_string()),
None => None,
}
},
_ => None
}
},
_ => None
}
}

View File

@ -17,7 +17,6 @@ mod env;
mod errors;
mod evaluate;
mod format;
mod git;
mod object;
mod parser;
mod plugin;

View File

@ -1,4 +1,6 @@
use crate::git::current_branch;
use git2::{Repository, RepositoryOpenFlags};
use std::ffi::OsString;
use crate::prelude::*;
pub struct Prompt;
@ -19,3 +21,20 @@ impl Prompt {
)
}
}
pub fn current_branch() -> Option<String> {
let v: Vec<OsString> = vec![];
match Repository::open_ext(".", RepositoryOpenFlags::empty(), v) {
Ok(repo) => {
let r = repo.head();
match r {
Ok(r) => match r.shorthand() {
Some(s) => Some(s.to_string()),
None => None,
},
_ => None,
}
}
_ => None,
}
}