From 71b9567437667005faa5212c827e79e0e14f05a0 Mon Sep 17 00:00:00 2001 From: Rene Pfeuffer Date: Wed, 8 Jan 2020 16:35:46 +0100 Subject: [PATCH] Fix reduce error with empty diff --- scm-ui/ui-components/src/repos/DiffFile.tsx | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/scm-ui/ui-components/src/repos/DiffFile.tsx b/scm-ui/ui-components/src/repos/DiffFile.tsx index cab227bbd5..634376626d 100644 --- a/scm-ui/ui-components/src/repos/DiffFile.tsx +++ b/scm-ui/ui-components/src/repos/DiffFile.tsx @@ -174,7 +174,7 @@ class DiffFile extends React.Component { }; renderHunk = (hunk: HunkType, i: number) => { - if (this.props.markConflicts) { + if (this.props.markConflicts && hunk.changes) { this.markConflicts(hunk); } return [ @@ -241,6 +241,14 @@ class DiffFile extends React.Component { return ; }; + concat = (array: object[][]) => { + if (array.length > 0) { + return array.reduce((a, b) => a.concat(b)); + } else { + return []; + } + }; + render() { const { file, fileControlFactory, fileAnnotationFactory, t } = this.props; const { collapsed, sideBySide } = this.state; @@ -255,7 +263,7 @@ class DiffFile extends React.Component {
{fileAnnotations} - {(hunks: HunkType[]) => hunks.map(this.renderHunk).reduce((a, b) => a.concat(b))} + {(hunks: HunkType[]) => this.concat(hunks.map(this.renderHunk))}
);