@@ -142,7 +142,7 @@ const getParsedData = (headerLines: string[]) => {
142
142
143
143
switch ( key ) {
144
144
case 'tree' :
145
- if ( parsedData . tree ) {
145
+ if ( parsedData . tree !== '' ) {
146
146
throw new Error ( 'Multiple tree lines found in commit.' ) ;
147
147
}
148
148
parsedData . tree = value . trim ( ) ;
@@ -151,13 +151,13 @@ const getParsedData = (headerLines: string[]) => {
151
151
parsedData . parents . push ( value . trim ( ) ) ;
152
152
break ;
153
153
case 'author' :
154
- if ( parsedData . author ) {
154
+ if ( ! isBlankPersonLine ( parsedData . author ) ) {
155
155
throw new Error ( 'Multiple author lines found in commit.' ) ;
156
156
}
157
157
parsedData . author = parsePersonLine ( value ) ;
158
158
break ;
159
159
case 'committer' :
160
- if ( parsedData . committer ) {
160
+ if ( ! isBlankPersonLine ( parsedData . committer ) ) {
161
161
throw new Error ( 'Multiple committer lines found in commit.' ) ;
162
162
}
163
163
parsedData . committer = parsePersonLine ( value ) ;
@@ -176,20 +176,29 @@ const getParsedData = (headerLines: string[]) => {
176
176
*/
177
177
const validateParsedData = ( parsedData : CommitHeader ) => {
178
178
const missing = [ ] ;
179
- if ( ! parsedData . tree ) {
179
+ if ( parsedData . tree === '' ) {
180
180
missing . push ( 'tree' ) ;
181
181
}
182
- if ( ! parsedData . author ) {
182
+ if ( isBlankPersonLine ( parsedData . author ) ) {
183
183
missing . push ( 'author' ) ;
184
184
}
185
- if ( ! parsedData . committer ) {
185
+ if ( isBlankPersonLine ( parsedData . committer ) ) {
186
186
missing . push ( 'committer' ) ;
187
187
}
188
188
if ( missing . length > 0 ) {
189
189
throw new Error ( `Invalid commit data: Missing ${ missing . join ( ', ' ) } ` ) ;
190
190
}
191
191
}
192
192
193
+ /**
194
+ * Checks if a person line is blank.
195
+ * @param {PersonLine } personLine - The person line to check.
196
+ * @return {boolean } True if the person line is blank, false otherwise.
197
+ */
198
+ const isBlankPersonLine = ( personLine : PersonLine ) : boolean => {
199
+ return personLine . name === '' && personLine . email === '' && personLine . timestamp === '' ;
200
+ }
201
+
193
202
/**
194
203
* Parses the commit data from the contents of a pack file.
195
204
* @param {CommitContent[] } contents - The contents of the pack file.
0 commit comments