You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
modify setup to choose pre-push hook with spellcheck
It changes setup for pre-push hook to use 3 options (tidy, with spellcheck, and skip).
Since spellceck binary is installed everytime under ./build if the user clean up the build folder,
it should be optional.
// The git hook has already been set up, or the user already has a custom hook.
498
-
returnOk(());
499
-
}
500
542
501
543
println!(
502
544
"\nRust's CI will automatically fail if it doesn't pass `tidy`, the internal tool for ensuring code quality.
503
545
If you'd like, x.py can install a git hook for you that will automatically run `test tidy` before
504
546
pushing your code to ensure your code is up to par. If you decide later that this behavior is
505
-
undesirable, simply delete the `pre-push` file from .git/hooks."
547
+
undesirable, simply delete the `pre-push` file from .git/hooks.
548
+
You have two choices of hooks, the first just runs `test tidy`, the second runs the tidy command with spellcheck.
549
+
Since the spellcheck will be installed if the binary doesn't exist under `build/`, we'll recommend you to choose the first one if you frequently clean up the build directory.
550
+
It overides the existing pre-push hoook if you already have."
506
551
);
507
552
508
-
ifprompt_user("Would you like to install the git hook?: [y/N]")? != Some(PromptResult::Yes){
509
-
println!("Ok, skipping installation!");
510
-
returnOk(());
511
-
}
553
+
let src = matchGitHookKind::prompt_user(){
554
+
Ok(git_hook_kind) => {
555
+
ifletSome(git_hook_kind) = git_hook_kind {
556
+
git_hook_kind.settings_path()
557
+
}else{
558
+
println!("Skip setting pre-push hook");
559
+
returnOk(());
560
+
}
561
+
},
562
+
Err(e) => {
563
+
eprintln!("ERROR: could not determine pre push hook: {e}");
564
+
returnErr(e);
565
+
}
566
+
};
567
+
512
568
if !hooks_dir.exists(){
513
569
// We need to (try to) create the hooks directory first.
514
570
let _ = fs::create_dir(hooks_dir);
515
571
}
516
-
let src = config.src.join("src").join("etc").join("pre-push.sh");
517
-
match fs::hard_link(src,&dst){
572
+
573
+
ifletOk(exist) = fs::exists(&dst) && exist {
574
+
// Remove the existing pre-push file.
575
+
ifletErr(e) = fs::remove_file(&dst){
576
+
eprintln!("ERROR: could not remove the existing hook\n{}", e);
577
+
returnErr(e);
578
+
}
579
+
}
580
+
581
+
match fs::hard_link(config.src.join(&src),&dst){
518
582
Err(e) => {
519
583
eprintln!(
520
-
"ERROR: could not create hook {}: do you already have the git hook installed?\n{}",
584
+
"ERROR: could not create hook {}:\n{}",
521
585
dst.display(),
522
586
e
523
587
);
524
588
returnErr(e);
525
589
}
526
-
Ok(_) => println!("Linked `src/etc/pre-push.sh` to `.git/hooks/pre-push`"),
590
+
Ok(_) => println!("Linked `{}` to `{}`", src.display(), dst.display()),
0 commit comments