File tree Expand file tree Collapse file tree 2 files changed +19
-4
lines changed Expand file tree Collapse file tree 2 files changed +19
-4
lines changed Original file line number Diff line number Diff line change @@ -543,8 +543,8 @@ fn debug_print() {
543
543
) ;
544
544
545
545
let mut command_with_removed_env = Command :: new ( "boring-name" ) ;
546
- command_with_removed_env. env_remove ( "BAR" ) ;
547
- assert_eq ! ( format!( "{command_with_removed_env:?}" ) , r#"unset( BAR) "boring-name""# ) ;
546
+ command_with_removed_env. env_remove ( "FOO" ) . env_remove ( " BAR") ;
547
+ assert_eq ! ( format!( "{command_with_removed_env:?}" ) , r#"unset BAR FOO && "boring-name""# ) ;
548
548
assert_eq ! (
549
549
format!( "{command_with_removed_env:#?}" ) ,
550
550
format!(
@@ -557,6 +557,7 @@ fn debug_print() {
557
557
clear: false,
558
558
vars: {{
559
559
"BAR": None,
560
+ "FOO": None,
560
561
}},
561
562
}},
562
563
{PIDFD}}}"#
Original file line number Diff line number Diff line change @@ -558,11 +558,25 @@ impl fmt::Debug for Command {
558
558
if let Some ( ref cwd) = self . cwd {
559
559
write ! ( f, "cd {cwd:?} && " ) ?;
560
560
}
561
+ // Removed env vars need a separate command.
562
+ // We use a single `unset` command for all of them.
563
+ let mut any_removed = false ;
564
+ for ( key, value_opt) in self . get_envs ( ) {
565
+ if value_opt. is_none ( ) {
566
+ if !any_removed {
567
+ write ! ( f, "unset " ) ?;
568
+ any_removed = true ;
569
+ }
570
+ write ! ( f, "{} " , key. to_string_lossy( ) ) ?;
571
+ }
572
+ }
573
+ if any_removed {
574
+ write ! ( f, "&& " ) ?;
575
+ }
576
+ // Altered env vars can just be added in front of the program.
561
577
for ( key, value_opt) in self . get_envs ( ) {
562
578
if let Some ( value) = value_opt {
563
579
write ! ( f, "{}={value:?} " , key. to_string_lossy( ) ) ?;
564
- } else {
565
- write ! ( f, "unset({}) " , key. to_string_lossy( ) ) ?;
566
580
}
567
581
}
568
582
if self . program != self . args [ 0 ] {
You can’t perform that action at this time.
0 commit comments