diff options
author | Gabriel de Perthuis <g2p.code@gmail.com> | 2020-11-26 19:56:18 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-26 19:56:18 +0100 |
commit | 3dfe4ca932b80a54f1ab809d106558b003e61e0d (patch) | |
tree | b83051079e956e4afc4f00801a5e485852106bb1 /src/modules/git_state.rs | |
parent | a20c7e2b17f5caa571b180803665cb512bc331ee (diff) |
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
Diffstat (limited to 'src/modules/git_state.rs')
-rw-r--r-- | src/modules/git_state.rs | 21 |
1 files 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, } } |