summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/modules/directory.rs5
-rw-r--r--tests/testsuite/directory.rs31
2 files changed, 34 insertions, 2 deletions
diff --git a/src/modules/directory.rs b/src/modules/directory.rs
index 01cd6c011..4bab47c71 100644
--- a/src/modules/directory.rs
+++ b/src/modules/directory.rs
@@ -8,7 +8,8 @@ use super::{Context, Module};
///
/// Will perform path contraction and truncation.
/// **Contraction**
-/// - Paths beginning with the home directory will be contracted to `~`
+/// - Paths beginning with the home directory or with a git repo right
+/// inside the home directory will be contracted to `~`
/// - Paths containing a git repo will contract to begin at the repo root
///
/// **Truncation**
@@ -57,7 +58,7 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
let repo = &context.get_repo().ok()?;
let dir_string = match &repo.root {
- Some(repo_root) if truncate_to_repo => {
+ Some(repo_root) if truncate_to_repo && (repo_root != &home_dir) => {
let repo_folder_name = repo_root.file_name().unwrap().to_str().unwrap();
// Contract the path to the git repo root
diff --git a/tests/testsuite/directory.rs b/tests/testsuite/directory.rs
index 25926a240..86f2aefd9 100644
--- a/tests/testsuite/directory.rs
+++ b/tests/testsuite/directory.rs
@@ -421,6 +421,37 @@ fn directory_in_git_repo_truncate_to_repo_true() -> io::Result<()> {
#[test]
#[ignore]
+#[cfg(not(target_os = "windows"))]
+fn git_repo_in_home_directory_truncate_to_repo_true() -> io::Result<()> {
+ let tmp_dir = TempDir::new_in(dirs::home_dir().unwrap())?;
+ let dir = tmp_dir.path().join("src/meters/fuel-gauge");
+ fs::create_dir_all(&dir)?;
+ Repository::init(&tmp_dir).unwrap();
+
+ let output = common::render_module("directory")
+ .use_config(toml::toml! {
+ [directory]
+ // `truncate_to_repo = true` should attmpt to display the truncated path
+ truncate_to_repo = true
+ truncation_length = 5
+ })
+ // Set home directory to the temp repository
+ .env("HOME", tmp_dir.path())
+ .arg("--path")
+ .arg(dir)
+ .output()?;
+ let actual = String::from_utf8(output.stdout).unwrap();
+
+ let expected = format!(
+ "in {} ",
+ Color::Cyan.bold().paint("~/src/meters/fuel-gauge")
+ );
+ assert_eq!(expected, actual);
+ Ok(())
+}
+
+#[test]
+#[ignore]
fn use_logical_and_physical_paths() -> io::Result<()> {
/* This test is a bit of a smoke + mirrors trick because all it shows is that
the application is reading the PWD envar correctly (if the shell doesn't