File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -496,10 +496,16 @@ fn os_family(_context: Context) -> FunctionResult {
496496}
497497
498498fn parent_directory ( _context : Context , path : & str ) -> FunctionResult {
499- Utf8Path :: new ( path)
499+ let parent = Utf8Path :: new ( path)
500500 . parent ( )
501501 . map ( Utf8Path :: to_string)
502- . ok_or_else ( || format ! ( "Could not extract parent directory from `{path}`" ) )
502+ . ok_or_else ( || format ! ( "Could not extract parent directory from `{path}`" ) ) ?;
503+
504+ if parent. is_empty ( ) {
505+ Ok ( "." . into ( ) )
506+ } else {
507+ Ok ( parent)
508+ }
503509}
504510
505511fn path_exists ( context : Context , path : & str ) -> FunctionResult {
Original file line number Diff line number Diff line change @@ -325,6 +325,19 @@ fn broken_directory_function2() {
325325 . failure ( ) ;
326326}
327327
328+ #[ test]
329+ fn parent_directory_of_bare_filename ( ) {
330+ Test :: new ( )
331+ . justfile (
332+ "
333+ foo:
334+ @echo {{parent_directory('foo')}}
335+ " ,
336+ )
337+ . stdout ( ".\n " )
338+ . success ( ) ;
339+ }
340+
328341#[ test]
329342fn env_var_functions_windows ( ) {
330343 if cfg ! ( not( windows) ) {
You can’t perform that action at this time.
0 commit comments