From 4d7b205e7fbfe6f5c8be7ef9c3367f3ce3e0afcd Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Wed, 22 Apr 2026 13:23:23 -0700 Subject: [PATCH 1/2] Make `parent_directory()` of relative file return `.` --- src/function.rs | 10 ++++++++-- tests/functions.rs | 13 +++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/function.rs b/src/function.rs index 2e31e196e8..e0fc2c77ad 100644 --- a/src/function.rs +++ b/src/function.rs @@ -496,10 +496,16 @@ fn os_family(_context: Context) -> FunctionResult { } fn parent_directory(_context: Context, path: &str) -> FunctionResult { - Utf8Path::new(path) + let parent = Utf8Path::new(path) .parent() .map(Utf8Path::to_string) - .ok_or_else(|| format!("Could not extract parent directory from `{path}`")) + .ok_or_else(|| format!("Could not extract parent directory from `{path}`"))?; + + if parent.is_empty() { + Ok(".".into()) + } else { + Ok(parent) + } } fn path_exists(context: Context, path: &str) -> FunctionResult { diff --git a/tests/functions.rs b/tests/functions.rs index a9eba0b980..82e7441516 100644 --- a/tests/functions.rs +++ b/tests/functions.rs @@ -325,6 +325,19 @@ fn broken_directory_function2() { .failure(); } +#[test] +fn parent_directory_of_bare_filename() { + Test::new() + .justfile( + " + foo: + @echo {{parent_directory('foo') / 'bar'}} + ", + ) + .stdout("./bar\n") + .success(); +} + #[test] fn env_var_functions_windows() { if cfg!(not(windows)) { From 96cb8a007e808de64e8c333227978b0a0403e146 Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Wed, 22 Apr 2026 13:25:26 -0700 Subject: [PATCH 2/2] Reform --- tests/functions.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/functions.rs b/tests/functions.rs index 82e7441516..4d3c80c8a3 100644 --- a/tests/functions.rs +++ b/tests/functions.rs @@ -331,10 +331,10 @@ fn parent_directory_of_bare_filename() { .justfile( " foo: - @echo {{parent_directory('foo') / 'bar'}} + @echo {{parent_directory('foo')}} ", ) - .stdout("./bar\n") + .stdout(".\n") .success(); }