@@ -115,17 +115,21 @@ pub fn get_commit_info(
115
115
} )
116
116
}
117
117
118
- ///
118
+ /// if `message_limit` is set the message will be
119
+ /// limited to the first line and truncated to fit
119
120
pub fn get_message (
120
121
c : & Commit ,
121
- message_length_limit : Option < usize > ,
122
+ message_limit : Option < usize > ,
122
123
) -> String {
123
124
let msg = String :: from_utf8_lossy ( c. message_bytes ( ) ) ;
124
125
let msg = msg. trim ( ) ;
125
126
126
- message_length_limit . map_or_else (
127
+ message_limit . map_or_else (
127
128
|| msg. to_string ( ) ,
128
- |limit| msg. unicode_truncate ( limit) . 0 . to_string ( ) ,
129
+ |limit| {
130
+ let msg = msg. lines ( ) . next ( ) . unwrap_or_default ( ) ;
131
+ msg. unicode_truncate ( limit) . 0 . to_string ( )
132
+ } ,
129
133
)
130
134
}
131
135
@@ -164,6 +168,25 @@ mod tests {
164
168
Ok ( ( ) )
165
169
}
166
170
171
+ #[ test]
172
+ fn test_log_first_msg_line ( ) -> Result < ( ) > {
173
+ let file_path = Path :: new ( "foo" ) ;
174
+ let ( _td, repo) = repo_init_empty ( ) . unwrap ( ) ;
175
+ let root = repo. path ( ) . parent ( ) . unwrap ( ) ;
176
+ let repo_path = root. as_os_str ( ) . to_str ( ) . unwrap ( ) ;
177
+
178
+ File :: create ( & root. join ( file_path) ) ?. write_all ( b"a" ) ?;
179
+ stage_add_file ( repo_path, file_path) . unwrap ( ) ;
180
+ let c1 = commit ( repo_path, "subject\n body" ) . unwrap ( ) ;
181
+
182
+ let res = get_commits_info ( repo_path, & vec ! [ c1] , 50 ) . unwrap ( ) ;
183
+
184
+ assert_eq ! ( res. len( ) , 1 ) ;
185
+ assert_eq ! ( res[ 0 ] . message. as_str( ) , "subject" ) ;
186
+
187
+ Ok ( ( ) )
188
+ }
189
+
167
190
#[ test]
168
191
fn test_invalid_utf8 ( ) -> Result < ( ) > {
169
192
let file_path = Path :: new ( "foo" ) ;
0 commit comments