Skip to content

Commit fd57e08

Browse files
committed
💥 Color scheme specification now mandatory with git hook
When running as the git commit hook, we now require the color scheme to be explicitly specified. If it's not specified, we ask the user to re-install the hook (which is just one command). Otherwise, the autodection will kick in and on some operating systems, we face the garbage input issue (#69).
1 parent e9906d6 commit fd57e08

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

‎src/main.rs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use std::{
1616
error::Error,
1717
fs::File,
1818
io::{BufRead, BufReader, Write},
19-
process,
19+
process::{self, exit},
2020
};
2121
#[cfg(unix)]
2222
use std::{fs::Permissions, os::unix::prelude::PermissionsExt};
@@ -246,9 +246,17 @@ fn get_color_scheme(args: &Args) -> ColorScheme {
246246
_ => None,
247247
})
248248
.or(args.color_scheme)
249-
.unwrap_or_else(|| match terminal_light::luma() {
250-
Ok(luma) if luma > 0.6 => ColorScheme::Light,
251-
_ => ColorScheme::Dark,
249+
.unwrap_or_else(|| {
250+
if args.hook.is_empty() {
251+
match terminal_light::luma() {
252+
Ok(luma) if luma > 0.6 => ColorScheme::Light,
253+
_ => ColorScheme::Dark,
254+
}
255+
} else {
256+
eprintln!("{}", NO_SCHEME_IN_HOOK_ERROR);
257+
258+
exit(-1);
259+
}
252260
})
253261
}
254262

@@ -259,3 +267,6 @@ const HOOK_CONTENT_TEMPL: &str = r#"
259267
exec < /dev/tty
260268
gimoji {color_scheme_arg} --hook $1 $2
261269
"#;
270+
271+
const NO_SCHEME_IN_HOOK_ERROR: &str =
272+
r#"No color scheme specified in the git hook. Please re-install it using `gimoji -i`."#;

0 commit comments

Comments
 (0)