Skip to content

Commit

Permalink
Merge pull request #63 from zeenix/expand-emoji-search
Browse files Browse the repository at this point in the history
🚸 Skip emoji injection if any part of commit has emoji
  • Loading branch information
zeenix authored Jan 2, 2024
2 parents 97e6be8 + e1d347f commit d32c506
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use selection_view::SelectionView;
use std::{
error::Error,
fs::File,
io::{Read, Write},
io::{BufRead, BufReader, Write},
};
#[cfg(unix)]
use std::{fs::Permissions, os::unix::prelude::PermissionsExt};
Expand Down Expand Up @@ -58,14 +58,15 @@ fn main() -> Result<(), Box<dyn Error>> {

let (commit_file_path, commit_file_content) = if !args.hook.is_empty() {
let path = &args.hook[0];
let mut file = File::open(path)?;
let file = File::open(path)?;
let mut reader = BufReader::new(file);
let mut content = String::new();
file.read_to_string(&mut content)?;
reader.read_line(&mut content)?;
let content = if !content.is_empty() {
// FIXME: There has to be a faster way to detect an emoji.
for emoji in emoji::EMOJIS {
if content.starts_with(emoji.emoji()) || content.starts_with(emoji.code()) {
// The file already contains an emoji.
if content.contains(emoji.emoji()) || content.contains(emoji.code()) {
// The commit shortlog already contains an emoji.
return Ok(());
}
}
Expand Down

0 comments on commit d32c506

Please sign in to comment.