Skip to content

Commit 917a306

Browse files
authored
Make [env] override module-level exports (#3312)
1 parent 6e74be2 commit 917a306

2 files changed

Lines changed: 41 additions & 8 deletions

File tree

src/recipe.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -359,14 +359,14 @@ impl<'src> Recipe<'src> {
359359
cmd.stdout(Stdio::null());
360360
}
361361

362+
cmd.export(settings, context.dotenv, scope, &context.module.unexports);
363+
362364
for attribute in &self.attributes {
363365
if let Attribute::Env(key, value) = attribute {
364366
cmd.env(&key.cooked, &value.cooked);
365367
}
366368
}
367369

368-
cmd.export(settings, context.dotenv, scope, &context.module.unexports);
369-
370370
let (result, caught) = cmd.status_guard();
371371

372372
match result {
@@ -524,19 +524,19 @@ impl<'src> Recipe<'src> {
524524
command.args(positional);
525525
}
526526

527-
for attribute in &self.attributes {
528-
if let Attribute::Env(key, value) = attribute {
529-
command.env(&key.cooked, &value.cooked);
530-
}
531-
}
532-
533527
command.export(
534528
&context.module.settings,
535529
context.dotenv,
536530
scope,
537531
&context.module.unexports,
538532
);
539533

534+
for attribute in &self.attributes {
535+
if let Attribute::Env(key, value) = attribute {
536+
command.env(&key.cooked, &value.cooked);
537+
}
538+
}
539+
540540
// run it!
541541
let (result, caught) = command.status_guard();
542542

tests/attributes.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,39 @@ fn env_attribute_too_many_arguments() {
428428
.failure();
429429
}
430430

431+
#[test]
432+
fn env_attribute_overrides_export() {
433+
Test::new()
434+
.justfile(
435+
"
436+
export FOO := 'export'
437+
438+
[env('FOO', 'attribute')]
439+
bar:
440+
@echo $FOO
441+
",
442+
)
443+
.stdout("attribute\n")
444+
.success();
445+
}
446+
447+
#[test]
448+
fn env_attribute_overrides_export_in_script() {
449+
Test::new()
450+
.justfile(
451+
"
452+
export FOO := 'export'
453+
454+
[env('FOO', 'attribute')]
455+
bar:
456+
#!/bin/sh
457+
echo $FOO
458+
",
459+
)
460+
.stdout("attribute\n")
461+
.success();
462+
}
463+
431464
#[test]
432465
fn env_attribute_duplicate_error() {
433466
Test::new()

0 commit comments

Comments
 (0)