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:
parent
9033bc38bb
commit
0c3c24104d
21
src/git.rs
21
src/git.rs
|
@ -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
|
||||
}
|
||||
}
|
|
@ -17,7 +17,6 @@ mod env;
|
|||
mod errors;
|
||||
mod evaluate;
|
||||
mod format;
|
||||
mod git;
|
||||
mod object;
|
||||
mod parser;
|
||||
mod plugin;
|
||||
|
|
|
@ -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,
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user