MCPcopy Index your code
hub / github.com/desktop/desktop / buildSubmoduleDiff

Function buildSubmoduleDiff

app/src/lib/git/diff.ts:765–809  ·  view source on GitHub ↗
(
  buffer: Buffer,
  repository: Repository,
  file: FileChange,
  status: SubmoduleStatus
)

Source from the content-addressed store, hash-verified

763}
764
765async 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
811async function buildDiff(
812 buffer: Buffer,

Callers 1

buildDiffFunction · 0.85

Calls 3

getConfigValueFunction · 0.90
lineMatchFunction · 0.85
toStringMethod · 0.45

Tested by

no test coverage detected