diff --git a/CHANGELOG.md b/CHANGELOG.md index 120b9578e..59d42d5c9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -62,6 +62,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * You now get a proper error message instead of a crash when `$EDITOR` doesn't exist or exits with an error. +* Fixed relative path to the current directory in output to be `.` instead of + empty string. + ## [0.4.0] - 2022-04-02 ### Breaking changes diff --git a/src/ui.rs b/src/ui.rs index f32e61aca..324e4e525 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -190,13 +190,19 @@ pub fn relative_path(mut from: &Path, to: &Path) -> PathBuf { let mut result = PathBuf::from(""); loop { if let Ok(suffix) = to.strip_prefix(from) { - return result.join(suffix); + result = result.join(suffix); + break; } if let Some(parent) = from.parent() { result = result.join(".."); from = parent; } else { - return to.to_owned(); + result = to.to_path_buf(); + break; } } + if result.as_os_str().is_empty() { + result = PathBuf::from("."); + } + result } diff --git a/tests/test_init_command.rs b/tests/test_init_command.rs index 69defa1fd..869f4815e 100644 --- a/tests/test_init_command.rs +++ b/tests/test_init_command.rs @@ -117,8 +117,7 @@ fn test_init_git_colocated() { let workspace_root = test_env.env_root().join("repo"); init_git_repo(&workspace_root); let stdout = test_env.jj_cmd_success(&workspace_root, &["init", "--git-repo", "."]); - // TODO: We should say "." instead of "" here - insta::assert_snapshot!(stdout, @r###"Initialized repo in "" + insta::assert_snapshot!(stdout, @r###"Initialized repo in "." "###); let jj_path = workspace_root.join(".jj");