* Returns a list of files that have been modified, deleted or added between specified commits.
(options: GitLogOptions = {})
| 288 | * Returns a list of files that have been modified, deleted or added between specified commits. |
| 289 | */ |
| 290 | async logFilesAsync(options: GitLogOptions = {}): Promise<GitFileLog[]> { |
| 291 | const fromCommit = options.fromCommit ?? ''; |
| 292 | const toCommit = options.toCommit ?? 'HEAD'; |
| 293 | |
| 294 | // This diff command returns a list of relative paths of files that have changed preceded by their status. |
| 295 | // Status is just a letter, which is also a key of `GitFileStatus` enum. |
| 296 | const { stdout } = await this.runAsync([ |
| 297 | 'diff', |
| 298 | '--name-status', |
| 299 | `${fromCommit}..${toCommit}`, |
| 300 | '--relative', |
| 301 | '--', |
| 302 | '.', |
| 303 | ]); |
| 304 | |
| 305 | return stdout |
| 306 | .split(/\n/g) |
| 307 | .filter(Boolean) |
| 308 | .map((line) => { |
| 309 | // Consecutive columns are separated by horizontal tabs. |
| 310 | // In case of `R` (rename) status, there are three columns instead of two, |
| 311 | // where the third is the new path after renaming and we should use the new one. |
| 312 | const [status, relativePath, relativePathAfterRename] = line.split(/\t+/g); |
| 313 | const newPath = relativePathAfterRename ?? relativePath; |
| 314 | |
| 315 | return { |
| 316 | relativePath: newPath, |
| 317 | path: join(this.path, newPath), |
| 318 | // `R` status also has a number, but we take care of only the first character. |
| 319 | status: GitFileStatus[status[0]] ?? status, |
| 320 | }; |
| 321 | }); |
| 322 | } |
| 323 | |
| 324 | /** |
| 325 | * Adds files at given glob paths. |
no test coverage detected