@@ -50,6 +50,9 @@ export class Git {
5050 *
5151 * @param options Options for the commit entry.
5252 * @param options.merge Set to `true` to generate a merge message line.
53+ * @param options.eol Choose the end of line character to use. Defaults to 'CRLF'.
54+ * 'LF' = '\n',
55+ * 'CRLF' = '\r\n'
5356 *
5457 * @example
5558 * faker.git.commitEntry()
@@ -59,17 +62,30 @@ export class Git {
5962 * //
6063 * // copy primary system
6164 */
62- commitEntry ( options : { merge ?: boolean } = { } ) : string {
63- // TODO @Shinigami 92 2022-01-11: We may want to make it configurable to use just `\n` instead of `\r\n`
64- let entry = `commit ${ this . commitSha ( ) } \r\n` ;
65+ commitEntry (
66+ options : {
67+ merge ?: boolean ;
68+ eol ?: 'LF' | 'CRLF' ;
69+ } = { }
70+ ) : string {
71+ const lines = [ `commit ${ this . faker . git . commitSha ( ) } ` ] ;
6572
6673 if ( options . merge || this . faker . datatype . number ( { min : 0 , max : 4 } ) === 0 ) {
67- entry += `Merge: ${ this . shortSha ( ) } } ${ this . shortSha ( ) } \r\n` ;
74+ lines . push ( `Merge: ${ this . shortSha ( ) } ${ this . shortSha ( ) } ` ) ;
6875 }
6976
70- entry += `Author: ${ this . faker . name . firstName ( ) } ${ this . faker . name . lastName ( ) } <${ this . faker . internet . email ( ) } >\r\n` ;
71- entry += `Date: ${ this . faker . date . recent ( ) . toString ( ) } \r\n` ;
72- entry += `\r\n\xa0\xa0\xa0\xa0${ this . commitMessage ( ) } \r\n` ;
77+ lines . push (
78+ `Author: ${ this . faker . name . firstName ( ) } ${ this . faker . name . lastName ( ) } <${ this . faker . internet . email ( ) } >` ,
79+ `Date: ${ this . faker . date . recent ( ) . toString ( ) } ` ,
80+ '' ,
81+ `\xa0\xa0\xa0\xa0${ this . commitMessage ( ) } ` ,
82+ // to end with a eol char
83+ ''
84+ ) ;
85+
86+ const eolOption = options . eol ?? 'CRLF' ;
87+ const eolChar = eolOption === 'CRLF' ? '\r\n' : '\n' ;
88+ const entry = lines . join ( eolChar ) ;
7389
7490 return entry ;
7591 }
0 commit comments