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],
overrides: &BTreeMap<String, String>,
) -> Result<(), Error<'src>> {
if config.unstable && config.search_config == SearchConfig::FromInvocationDirectory {
let mut path = config.invocation_directory.clone();
if config.unstable
&& 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;

View File

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