Skip to content

Commit 007b244

Browse files
committed
Revert pass-through of global install flags into generated hook scripts (#1966)
Closes #1965 Reverts #1753. I agree that passing global flags down into installed scripts is not a good idea, so this reverts that behavior. We can add dedicated install flags later if we want explicit inherit behavior.
1 parent b66c39c commit 007b244

3 files changed

Lines changed: 1 addition & 194 deletions

File tree

crates/prek/src/cli/install.rs

Lines changed: 1 addition & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,6 @@ pub(crate) async fn install(
3333
overwrite: bool,
3434
allow_missing_config: bool,
3535
refresh: bool,
36-
quiet: u8,
37-
verbose: u8,
38-
no_progress: bool,
3936
printer: Printer,
4037
git_dir: Option<&Path>,
4138
) -> Result<ExitStatus> {
@@ -117,9 +114,6 @@ pub(crate) async fn install(
117114
overwrite,
118115
allow_missing_config,
119116
hook_mode,
120-
quiet,
121-
verbose,
122-
no_progress,
123117
printer,
124118
)?;
125119
}
@@ -212,9 +206,6 @@ fn install_hook_script(
212206
overwrite: bool,
213207
skip_on_missing_config: bool,
214208
hook_mode: u32,
215-
quiet: u8,
216-
verbose: u8,
217-
no_progress: bool,
218209
printer: Printer,
219210
) -> Result<()> {
220211
let hook_path = hooks_path.join(hook_type.as_ref());
@@ -321,14 +312,9 @@ fn install_hook_script(
321312

322313
let prek = std::env::current_exe()?;
323314
let prek = prek.simplified_display().to_string();
324-
let mut prek_global_args = render_global_args(quiet, verbose, no_progress);
325-
if !prek_global_args.is_empty() {
326-
prek_global_args.push(' ');
327-
}
328315
let hook_script = HOOK_TMPL
329316
.replace("[CUR_SCRIPT_VERSION]", &CUR_SCRIPT_VERSION.to_string())
330317
.replace("[PREK_PATH]", &format!(r#""{prek}""#))
331-
.replace("[PREK_GLOBAL_ARGS]", &prek_global_args)
332318
.replace("[PREK_ARGS]", &args.join(" "));
333319

334320
fs_err::OpenOptions::new()
@@ -356,28 +342,6 @@ fn install_hook_script(
356342
Ok(())
357343
}
358344

359-
fn render_global_args(quiet: u8, verbose: u8, no_progress: bool) -> String {
360-
let mut args = Vec::with_capacity(3);
361-
362-
if quiet > 0 {
363-
args.push(format!("-{}", "q".repeat(quiet.into())));
364-
}
365-
366-
if verbose > 0 {
367-
args.push(format!("-{}", "v".repeat(verbose.into())));
368-
}
369-
370-
if no_progress {
371-
args.push("--no-progress".to_string());
372-
}
373-
374-
if args.is_empty() {
375-
String::new()
376-
} else {
377-
args.join(" ")
378-
}
379-
}
380-
381345
/// The version of the hook script. Increment this when the script changes in a way that
382346
/// requires re-installation.
383347
pub(crate) static CUR_SCRIPT_VERSION: usize = 4;
@@ -394,7 +358,7 @@ if [ ! -x "$PREK" ]; then
394358
PREK="prek"
395359
fi
396360
397-
exec "$PREK" [PREK_GLOBAL_ARGS]hook-impl --hook-dir "$HERE" --script-version [CUR_SCRIPT_VERSION] [PREK_ARGS] -- "$@"
361+
exec "$PREK" hook-impl --hook-dir "$HERE" --script-version [CUR_SCRIPT_VERSION] [PREK_ARGS] -- "$@"
398362
399363
"#;
400364

@@ -519,9 +483,6 @@ pub(crate) async fn init_template_dir(
519483
hook_types: Vec<HookType>,
520484
requires_config: bool,
521485
refresh: bool,
522-
quiet: u8,
523-
verbose: u8,
524-
no_progress: bool,
525486
printer: Printer,
526487
) -> Result<ExitStatus> {
527488
install(
@@ -534,9 +495,6 @@ pub(crate) async fn init_template_dir(
534495
true,
535496
!requires_config,
536497
refresh,
537-
quiet,
538-
verbose,
539-
no_progress,
540498
printer,
541499
Some(&directory),
542500
)

crates/prek/src/main.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -252,9 +252,6 @@ async fn run(cli: Cli) -> Result<ExitStatus> {
252252
args.overwrite,
253253
args.allow_missing_config,
254254
cli.globals.refresh,
255-
cli.globals.quiet,
256-
cli.globals.verbose,
257-
cli.globals.no_progress,
258255
printer,
259256
args.git_dir.as_deref(),
260257
)
@@ -434,9 +431,6 @@ async fn run(cli: Cli) -> Result<ExitStatus> {
434431
args.hook_types,
435432
args.no_allow_missing_config,
436433
cli.globals.refresh,
437-
cli.globals.quiet,
438-
cli.globals.verbose,
439-
cli.globals.no_progress,
440434
printer,
441435
)
442436
.await
@@ -496,9 +490,6 @@ async fn run(cli: Cli) -> Result<ExitStatus> {
496490
args.hook_types,
497491
args.no_allow_missing_config,
498492
cli.globals.refresh,
499-
cli.globals.quiet,
500-
cli.globals.verbose,
501-
cli.globals.no_progress,
502493
printer,
503494
)
504495
.await

crates/prek/tests/install.rs

Lines changed: 0 additions & 142 deletions
Original file line numberDiff line numberDiff line change
@@ -166,148 +166,6 @@ fn install() -> anyhow::Result<()> {
166166
Ok(())
167167
}
168168

169-
#[test]
170-
fn install_with_quiet_flag() {
171-
let context = TestContext::new();
172-
context.init_project();
173-
174-
cmd_snapshot!(context.filters(), context.install().arg("-q"), @r#"
175-
success: true
176-
exit_code: 0
177-
----- stdout -----
178-
179-
----- stderr -----
180-
"#);
181-
182-
insta::with_settings!(
183-
{ filters => context.filters() },
184-
{
185-
assert_snapshot!(context.read(".git/hooks/pre-commit"), @r#"
186-
#!/bin/sh
187-
# File generated by prek: https://github.com/j178/prek
188-
# ID: 182c10f181da4464a3eec51b83331688
189-
190-
HERE="$(cd "$(dirname "$0")" && pwd)"
191-
PREK="[CURRENT_EXE]"
192-
193-
# Check if the full path to prek is executable, otherwise fallback to PATH
194-
if [ ! -x "$PREK" ]; then
195-
PREK="prek"
196-
fi
197-
198-
exec "$PREK" -q hook-impl --hook-dir "$HERE" --script-version 4 --hook-type=pre-commit -- "$@"
199-
"#);
200-
}
201-
);
202-
}
203-
204-
#[test]
205-
fn install_with_silent_flag() {
206-
let context = TestContext::new();
207-
context.init_project();
208-
209-
cmd_snapshot!(context.filters(), context.install().arg("-qq"), @r#"
210-
success: true
211-
exit_code: 0
212-
----- stdout -----
213-
214-
----- stderr -----
215-
"#);
216-
217-
insta::with_settings!(
218-
{ filters => context.filters() },
219-
{
220-
assert_snapshot!(context.read(".git/hooks/pre-commit"), @r#"
221-
#!/bin/sh
222-
# File generated by prek: https://github.com/j178/prek
223-
# ID: 182c10f181da4464a3eec51b83331688
224-
225-
HERE="$(cd "$(dirname "$0")" && pwd)"
226-
PREK="[CURRENT_EXE]"
227-
228-
# Check if the full path to prek is executable, otherwise fallback to PATH
229-
if [ ! -x "$PREK" ]; then
230-
PREK="prek"
231-
fi
232-
233-
exec "$PREK" -qq hook-impl --hook-dir "$HERE" --script-version 4 --hook-type=pre-commit -- "$@"
234-
"#);
235-
}
236-
);
237-
}
238-
239-
#[test]
240-
fn install_with_verbose_flag() {
241-
let context = TestContext::new();
242-
context.init_project();
243-
244-
cmd_snapshot!(context.filters(), context.install().arg("-v"), @r#"
245-
success: true
246-
exit_code: 0
247-
----- stdout -----
248-
prek installed at `.git/hooks/pre-commit`
249-
250-
----- stderr -----
251-
"#);
252-
253-
insta::with_settings!(
254-
{ filters => context.filters() },
255-
{
256-
assert_snapshot!(context.read(".git/hooks/pre-commit"), @r#"
257-
#!/bin/sh
258-
# File generated by prek: https://github.com/j178/prek
259-
# ID: 182c10f181da4464a3eec51b83331688
260-
261-
HERE="$(cd "$(dirname "$0")" && pwd)"
262-
PREK="[CURRENT_EXE]"
263-
264-
# Check if the full path to prek is executable, otherwise fallback to PATH
265-
if [ ! -x "$PREK" ]; then
266-
PREK="prek"
267-
fi
268-
269-
exec "$PREK" -v hook-impl --hook-dir "$HERE" --script-version 4 --hook-type=pre-commit -- "$@"
270-
"#);
271-
}
272-
);
273-
}
274-
275-
#[test]
276-
fn install_with_no_progress_flag() {
277-
let context = TestContext::new();
278-
context.init_project();
279-
280-
cmd_snapshot!(context.filters(), context.install().arg("--no-progress"), @r#"
281-
success: true
282-
exit_code: 0
283-
----- stdout -----
284-
prek installed at `.git/hooks/pre-commit`
285-
286-
----- stderr -----
287-
"#);
288-
289-
insta::with_settings!(
290-
{ filters => context.filters() },
291-
{
292-
assert_snapshot!(context.read(".git/hooks/pre-commit"), @r#"
293-
#!/bin/sh
294-
# File generated by prek: https://github.com/j178/prek
295-
# ID: 182c10f181da4464a3eec51b83331688
296-
297-
HERE="$(cd "$(dirname "$0")" && pwd)"
298-
PREK="[CURRENT_EXE]"
299-
300-
# Check if the full path to prek is executable, otherwise fallback to PATH
301-
if [ ! -x "$PREK" ]; then
302-
PREK="prek"
303-
fi
304-
305-
exec "$PREK" --no-progress hook-impl --hook-dir "$HERE" --script-version 4 --hook-type=pre-commit -- "$@"
306-
"#);
307-
}
308-
);
309-
}
310-
311169
#[test]
312170
fn install_with_git_dir() {
313171
let context = TestContext::new();

0 commit comments

Comments
 (0)