From 3dfe4ca932b80a54f1ab809d106558b003e61e0d Mon Sep 17 00:00:00 2001 From: Gabriel de Perthuis Date: Thu, 26 Nov 2020 19:56:18 +0100 Subject: [PATCH] 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 --- src/modules/git_state.rs | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/modules/git_state.rs b/src/modules/git_state.rs index 59ba36a6c..aefbc495c 100644 --- a/src/modules/git_state.rs +++ b/src/modules/git_state.rs @@ -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, } }