Only check for the git hooks directory in (un)install subcommands.

This commit is contained in:
Bauke 2022-10-31 14:22:49 +01:00
parent 91a5cc4203
commit 16757cabce
Signed by: Bauke
GPG Key ID: C1C0F29952BCF558
1 changed files with 8 additions and 3 deletions

View File

@ -35,12 +35,13 @@ fn main() -> Result<()> {
let config = Config::from_toml_file(args.config)?; let config = Config::from_toml_file(args.config)?;
let git_hooks_dir = PathBuf::from(".git/hooks/"); let git_hooks_dir = PathBuf::from(".git/hooks/");
if !git_hooks_dir.exists() {
return Err(eyre!("The \".git/hooks/\" directory does not exist"));
}
match args.command { match args.command {
MainSubcommands::Install { overwrite } => { MainSubcommands::Install { overwrite } => {
if !git_hooks_dir.exists() {
return Err(eyre!("The \".git/hooks/\" directory does not exist"));
}
for hook_type in HOOK_TYPES { for hook_type in HOOK_TYPES {
let mut context = Context::new(); let mut context = Context::new();
context.insert("hook_type", hook_type); context.insert("hook_type", hook_type);
@ -63,6 +64,10 @@ fn main() -> Result<()> {
} }
MainSubcommands::Uninstall { all } => { MainSubcommands::Uninstall { all } => {
if !git_hooks_dir.exists() {
return Err(eyre!("The \".git/hooks/\" directory does not exist"));
}
for hook_type in HOOK_TYPES { for hook_type in HOOK_TYPES {
let hook_path = git_hooks_dir.join(hook_type); let hook_path = git_hooks_dir.join(hook_type);
if !hook_path.exists() { if !hook_path.exists() {