Skip to content

Commit d32c506

Browse files
authored
Merge pull request #63 from zeenix/expand-emoji-search
🚸 Skip emoji injection if any part of commit has emoji
2 parents 97e6be8 + e1d347f commit d32c506

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/main.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use selection_view::SelectionView;
1515
use std::{
1616
error::Error,
1717
fs::File,
18-
io::{Read, Write},
18+
io::{BufRead, BufReader, Write},
1919
};
2020
#[cfg(unix)]
2121
use std::{fs::Permissions, os::unix::prelude::PermissionsExt};
@@ -58,14 +58,15 @@ fn main() -> Result<(), Box<dyn Error>> {
5858

5959
let (commit_file_path, commit_file_content) = if !args.hook.is_empty() {
6060
let path = &args.hook[0];
61-
let mut file = File::open(path)?;
61+
let file = File::open(path)?;
62+
let mut reader = BufReader::new(file);
6263
let mut content = String::new();
63-
file.read_to_string(&mut content)?;
64+
reader.read_line(&mut content)?;
6465
let content = if !content.is_empty() {
6566
// FIXME: There has to be a faster way to detect an emoji.
6667
for emoji in emoji::EMOJIS {
67-
if content.starts_with(emoji.emoji()) || content.starts_with(emoji.code()) {
68-
// The file already contains an emoji.
68+
if content.contains(emoji.emoji()) || content.contains(emoji.code()) {
69+
// The commit shortlog already contains an emoji.
6970
return Ok(());
7071
}
7172
}

0 commit comments

Comments
 (0)