Skip to content

Commit d79b8d5

Browse files
committed
Add comments
1 parent 1e05049 commit d79b8d5

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

crates/prek/src/languages/script.rs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ fn resolve_default_shell_spec() -> Result<ShellSpec> {
7777
if let Ok(path) = which::which("bash") {
7878
return Ok(ShellSpec {
7979
program: path.to_string_lossy().to_string(),
80+
// `-e` makes the script fail fast: stop on the first command that exits non-zero.
8081
prefix_args: vec!["-e".to_string()],
8182
extension: "sh",
8283
});
@@ -98,10 +99,15 @@ fn resolve_default_shell_spec() -> Result<ShellSpec> {
9899
return Ok(ShellSpec {
99100
program: path.to_string_lossy().to_string(),
100101
prefix_args: vec![
102+
// Avoid loading user profile scripts (deterministic and faster).
101103
"-NoProfile".to_string(),
104+
// Avoid prompts / interactive behavior.
102105
"-NonInteractive".to_string(),
106+
// Allow running a temp script file in CI environments where execution policy
107+
// would otherwise block it.
103108
"-ExecutionPolicy".to_string(),
104109
"Bypass".to_string(),
110+
// Execute a script file.
105111
"-File".to_string(),
106112
],
107113
extension: "ps1",
@@ -124,7 +130,15 @@ fn resolve_default_shell_spec() -> Result<ShellSpec> {
124130
if let Ok(path) = which::which("cmd") {
125131
return Ok(ShellSpec {
126132
program: path.to_string_lossy().to_string(),
127-
prefix_args: vec!["/d".to_string(), "/s".to_string(), "/c".to_string()],
133+
prefix_args: vec![
134+
// Disable execution of AutoRun commands from the registry (deterministic).
135+
"/d".to_string(),
136+
// Apply legacy parsing rules for the command string passed to /c.
137+
// This makes cmd.exe behavior more consistent when the command contains quotes.
138+
"/s".to_string(),
139+
// Run the command and then terminate.
140+
"/c".to_string(),
141+
],
128142
extension: "cmd",
129143
});
130144
}
@@ -182,7 +196,8 @@ async fn build_inline_entry(
182196
resolve_command(vec![script_path.to_string_lossy().to_string()], None)
183197
} else {
184198
// Execute via the chosen default shell by passing the script path.
185-
let spec = default_shell.expect("default_shell must be set if shebang is None");
199+
let spec = default_shell
200+
.ok_or_else(|| anyhow::anyhow!("default shell must be set if no shebang is present"))?;
186201
spec.build_for_script(&script_path)
187202
};
188203

0 commit comments

Comments
 (0)