Skip to content

Commit

Permalink
Make changes based on @jyn514's comments
Browse files Browse the repository at this point in the history
  • Loading branch information
caass committed Oct 6, 2020
1 parent d585c96 commit 0845627
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions src/bootstrap/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,12 @@ pub fn setup(src_path: &Path, include_name: &str) {
_ => return,
};

println!();

t!(install_git_hook_maybe(src_path));

println!();

println!("To get started, try one of the following commands:");
for cmd in suggestions {
println!("- `x.py {}`", cmd);
Expand Down Expand Up @@ -102,10 +106,10 @@ simply delete the `pre-commit` file from .git/hooks."
let should_install = loop {
print!("Would you like to install the git hook?: [y/N] ");
io::stdout().flush()?;
input.clear();
io::stdin().read_line(&mut input)?;
break match input.trim().to_lowercase().as_str() {
"y" | "yes" => true,
// is this the right way to check for "entered nothing"?
"n" | "no" | "" => false,
_ => {
println!("error: unrecognized option '{}'", input.trim());
Expand All @@ -115,14 +119,17 @@ simply delete the `pre-commit` file from .git/hooks."
};
};

if should_install {
let src = src_path.join("/etc/pre-commit.rs");
let dst = src_path.join("/.git/hooks/pre-commit");
fs::hard_link(src, dst)?;
println!("Linked `src/etc/pre-commit.sh` to `.git/hooks/pre-commit`");
Ok(if should_install {
let src = src_path.join("src").join("etc").join("pre-commit.sh");
let dst = src_path.join(".git").join("hooks").join("pre-commit");
match fs::hard_link(src, dst) {
Err(e) => println!(
"x.py encountered an error -- do you already have the git hook installed?\n{}",
e
),
Ok(_) => println!("Linked `src/etc/pre-commit.sh` to `.git/hooks/pre-commit`"),
};
} else {
println!("Ok, skipping installation!");
};

Ok(())
})
}

0 comments on commit 0845627

Please sign in to comment.