Allow fallback with search directory (#1348)

This loosens a restriction, and allows falling back to a justfile in a parent justfile
when a search directory is provide, e.g. with `just ..` or `just foo/bar/`. Looking
 at it now, I can't really think of why I enforced that restriction in the first place.
Hopefully it's not important 🤷‍♀️.
This commit is contained in:
Casey Rodarmor 2022-09-20 22:46:53 -07:00 committed by GitHub
parent e5350926b5
commit 76bda4cfd9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 5 deletions

View File

@ -92,8 +92,19 @@ impl Subcommand {
arguments: &[String], arguments: &[String],
overrides: &BTreeMap<String, String>, overrides: &BTreeMap<String, String>,
) -> Result<(), Error<'src>> { ) -> Result<(), Error<'src>> {
if config.unstable && config.search_config == SearchConfig::FromInvocationDirectory { if config.unstable
let mut path = config.invocation_directory.clone(); && matches!(
config.search_config,
SearchConfig::FromInvocationDirectory | SearchConfig::FromSearchDirectory { .. }
)
{
let mut path = match &config.search_config {
SearchConfig::FromInvocationDirectory => config.invocation_directory.clone(),
SearchConfig::FromSearchDirectory { search_directory } => std::env::current_dir()
.unwrap()
.join(search_directory.clone()),
_ => unreachable!(),
};
let mut unknown_recipes_errors = None; let mut unknown_recipes_errors = None;

View File

@ -83,7 +83,7 @@ fn requires_unstable() {
} }
#[test] #[test]
fn doesnt_work_with_search_directory() { fn works_with_provided_search_directory() {
Test::new() Test::new()
.tree(tree! { .tree(tree! {
bar: { bar: {
@ -100,9 +100,15 @@ fn doesnt_work_with_search_directory() {
", ",
) )
.args(&["--unstable", "./foo"]) .args(&["--unstable", "./foo"])
.stdout("root\n")
.stderr(format!(
"
Trying ..{}justfile
echo root
",
MAIN_SEPARATOR
))
.current_dir("bar") .current_dir("bar")
.status(EXIT_FAILURE)
.stderr("error: Justfile does not contain recipe `foo`.\n")
.run(); .run();
} }