mirror of
https://github.com/Llewellynvdm/starship.git
synced 2024-11-24 21:57:41 +00:00
fix(directory): don't strip duplicate directory names twice (#4295)
* Fix directory issue in a special case * add None test
This commit is contained in:
parent
98996f5846
commit
801fbab720
@ -111,7 +111,7 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
|
|||||||
|| ((num_segments_after_root - 1) as i64) < config.truncation_length
|
|| ((num_segments_after_root - 1) as i64) < config.truncation_length
|
||||||
{
|
{
|
||||||
let root = repo_path_vec[0];
|
let root = repo_path_vec[0];
|
||||||
let before = dir_string.replace(&contracted_path, "");
|
let before = before_root_dir(&dir_string, &contracted_path);
|
||||||
[prefix + before.as_str(), root.to_string(), after_repo_root]
|
[prefix + before.as_str(), root.to_string(), after_repo_root]
|
||||||
} else {
|
} else {
|
||||||
["".to_string(), "".to_string(), prefix + dir_string.as_str()]
|
["".to_string(), "".to_string(), prefix + dir_string.as_str()]
|
||||||
@ -339,6 +339,14 @@ fn convert_path_sep(path: &str) -> String {
|
|||||||
return PathBuf::from_slash(path).to_string_lossy().into_owned();
|
return PathBuf::from_slash(path).to_string_lossy().into_owned();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get the path before the git repo root by trim the most right repo name.
|
||||||
|
fn before_root_dir(path: &str, repo: &str) -> String {
|
||||||
|
match path.rsplit_once(repo) {
|
||||||
|
Some((a, _)) => a.to_string(),
|
||||||
|
None => path.to_string(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
@ -1788,4 +1796,22 @@ mod tests {
|
|||||||
assert_eq!(expected, actual);
|
assert_eq!(expected, actual);
|
||||||
tmp_dir.close()
|
tmp_dir.close()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn parent_and_sub_git_repo_are_in_same_name_folder() {
|
||||||
|
assert_eq!(
|
||||||
|
before_root_dir("~/user/gitrepo/gitrepo", "gitrepo"),
|
||||||
|
"~/user/gitrepo/".to_string()
|
||||||
|
);
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
before_root_dir("~/user/gitrepo-diff/gitrepo", "gitrepo"),
|
||||||
|
"~/user/gitrepo-diff/".to_string()
|
||||||
|
);
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
before_root_dir("~/user/gitrepo-diff/gitrepo", "aaa"),
|
||||||
|
"~/user/gitrepo-diff/gitrepo".to_string()
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user