1
0
mirror of https://github.com/Llewellynvdm/starship.git synced 2024-11-05 04:47:58 +00:00

fix(git_state): Handle gitdir indirection when rebasing (#1744)

* Make git_state more robust

No need to come up with fake progress info.

See #1374, #1761.

* git_state: add support for .git indirection when rebasing
This commit is contained in:
Gabriel de Perthuis 2020-11-26 19:56:18 +01:00 committed by GitHub
parent a20c7e2b17
commit 3dfe4ca932
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -114,6 +114,16 @@ fn describe_rebase<'a>(root: &'a PathBuf, rebase_config: &'a str) -> StateDescri
*/
let dot_git = root.join(".git");
let dot_git = if let Ok(conf) = std::fs::read_to_string(&dot_git) {
let gitdir_re = regex::Regex::new(r"(?m)^gitdir: (.*)$").unwrap();
if let Some(caps) = gitdir_re.captures(&conf) {
root.join(caps.get(1).unwrap().as_str())
} else {
dot_git
}
} else {
dot_git
};
let has_path = |relative_path: &str| {
let path = dot_git.join(PathBuf::from(relative_path));
@ -140,12 +150,17 @@ fn describe_rebase<'a>(root: &'a PathBuf, rebase_config: &'a str) -> StateDescri
} else {
None
};
let progress = progress.unwrap_or((1, 1));
let (current, total) = if let Some((c, t)) = progress {
(Some(format!("{}", c)), Some(format!("{}", t)))
} else {
(None, None)
};
StateDescription {
label: rebase_config,
current: Some(format!("{}", progress.0)),
total: Some(format!("{}", progress.1)),
current,
total,
}
}