@@ -2,7 +2,7 @@ use std::env;
2
2
use std:: error:: Error ;
3
3
use std:: fmt;
4
4
use std:: fs:: File ;
5
- use std:: io:: { BufRead , BufReader , Seek , Write , stderr, stdin} ;
5
+ use std:: io:: { Seek , Write , stderr, stdin} ;
6
6
use std:: process:: { Command , exit} ;
7
7
use std:: path:: PathBuf ;
8
8
use std:: str:: FromStr ;
@@ -12,12 +12,14 @@ use termion::input::TermRead;
12
12
use termion:: raw:: IntoRawMode ;
13
13
14
14
use emoji_commit_type:: CommitType ;
15
+ use message:: { git_parse_existing_message, git_message_is_empty} ;
15
16
use log_update:: LogUpdate ;
16
17
use structopt:: StructOpt ;
17
18
use ansi_term:: Colour :: { RGB , Green , Red , White } ;
18
19
19
20
mod commit_rules;
20
21
mod git;
22
+ mod message;
21
23
22
24
impl fmt:: Display for commit_rules:: CommitRuleValidationResult {
23
25
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
@@ -143,41 +145,6 @@ fn launch_git_with_self_as_editor() {
143
145
run_cmd ( Command :: new ( "git" ) . arg ( "commit" ) . env ( "GIT_EDITOR" , self_path) )
144
146
}
145
147
146
- fn git_parse_existing_message ( file : & mut File ) -> Option < ( CommitType , String ) > {
147
- let first_line = file. read_line ( ) . unwrap ( ) . unwrap ( ) ;
148
-
149
- if first_line. is_empty ( ) {
150
- return None ;
151
- }
152
-
153
-
154
- let first_str = first_line. chars ( ) . next ( ) . unwrap ( ) . to_string ( ) ;
155
-
156
- let commit_type = CommitType :: iter_variants ( ) . find ( |commit_type| {
157
- first_str == commit_type. emoji ( )
158
- } ) ;
159
-
160
- if commit_type == None { return None ; }
161
-
162
- // Check that the rest of the commit message is empty (i.e. no body)
163
- if !git_message_is_empty ( file) { return None ; }
164
-
165
- let emoji = commit_type. unwrap ( ) . emoji ( ) . to_string ( ) ;
166
- let message = first_line. replace ( & emoji, "" ) . trim ( ) . to_string ( ) ;
167
- Some ( ( commit_type. unwrap ( ) , message) )
168
- }
169
-
170
- fn git_message_is_empty ( file : & mut File ) -> bool {
171
- for line in BufReader :: new ( file) . lines ( ) {
172
- let line = line. expect ( "Failed to read line from git message file" ) ;
173
-
174
- if !line. starts_with ( '#' ) && !line. is_empty ( ) {
175
- return false ;
176
- }
177
- }
178
- true
179
- }
180
-
181
148
fn collect_information_and_write_to_file ( out_path : PathBuf ) {
182
149
let mut file = File :: options ( ) . read ( true ) . write ( true ) . create ( true ) . open ( & out_path) . unwrap ( ) ;
183
150
let mut initial_message: Option < String > = None ;
0 commit comments