( buffer: Buffer, repository: Repository, file: FileChange, status: SubmoduleStatus )
| 763 | } |
| 764 | |
| 765 | async function buildSubmoduleDiff( |
| 766 | buffer: Buffer, |
| 767 | repository: Repository, |
| 768 | file: FileChange, |
| 769 | status: SubmoduleStatus |
| 770 | ): Promise<IDiff> { |
| 771 | const path = file.path |
| 772 | const fullPath = Path.join(repository.path, path) |
| 773 | const url = await getConfigValue(repository, `submodule.${path}.url`, true) |
| 774 | |
| 775 | let oldSHA = null |
| 776 | let newSHA = null |
| 777 | |
| 778 | if ( |
| 779 | status.commitChanged || |
| 780 | file.status.kind === AppFileStatusKind.New || |
| 781 | file.status.kind === AppFileStatusKind.Deleted |
| 782 | ) { |
| 783 | const diff = buffer.toString('utf-8') |
| 784 | const lines = diff.split('\n') |
| 785 | const baseRegex = 'Subproject commit ([^-]+)(-dirty)?$' |
| 786 | const oldSHARegex = new RegExp('-' + baseRegex) |
| 787 | const newSHARegex = new RegExp('\\+' + baseRegex) |
| 788 | const lineMatch = (regex: RegExp) => |
| 789 | lines |
| 790 | .flatMap(line => { |
| 791 | const match = line.match(regex) |
| 792 | return match ? match[1] : [] |
| 793 | }) |
| 794 | .at(0) ?? null |
| 795 | |
| 796 | oldSHA = lineMatch(oldSHARegex) |
| 797 | newSHA = lineMatch(newSHARegex) |
| 798 | } |
| 799 | |
| 800 | return { |
| 801 | kind: DiffType.Submodule, |
| 802 | fullPath, |
| 803 | path, |
| 804 | url, |
| 805 | status, |
| 806 | oldSHA, |
| 807 | newSHA, |
| 808 | } |
| 809 | } |
| 810 | |
| 811 | async function buildDiff( |
| 812 | buffer: Buffer, |
no test coverage detected