From f63520bbef35baedd75a5e6ae3ea16c9a2de68c4 Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Sat, 28 Jan 2023 00:33:31 -0500 Subject: [PATCH] Fixes coerced stats type --- src/git/models/commit.ts | 10 +++++++++- src/plus/github/githubGitProvider.ts | 7 ++----- src/plus/webviews/timeline/timelineWebview.ts | 10 ++++++++-- src/plus/webviews/timeline/timelineWebviewView.ts | 10 ++++++++-- 4 files changed, 27 insertions(+), 10 deletions(-) diff --git a/src/git/models/commit.ts b/src/git/models/commit.ts index f7b5c67..9c8745b 100644 --- a/src/git/models/commit.ts +++ b/src/git/models/commit.ts @@ -364,7 +364,7 @@ export class GitCommit implements GitRevisionReference { if (stats == null) return options?.empty ?? ''; const { changedFiles, additions, deletions } = stats; - if (changedFiles <= 0 && additions <= 0 && deletions <= 0) return options?.empty ?? ''; + if (getChangedFilesCount(changedFiles) <= 0 && additions <= 0 && deletions <= 0) return options?.empty ?? ''; const { compact = false, @@ -650,6 +650,14 @@ export interface GitCommitStats { readonly changedFiles: number | { added: number; deleted: number; changed: number }; } +export function getChangedFilesCount(changedFiles: GitCommitStats['changedFiles'] | undefined): number { + if (changedFiles == null) return 0; + + return typeof changedFiles === 'number' + ? changedFiles + : changedFiles.added + changedFiles.changed + changedFiles.deleted; +} + export interface GitStashCommit extends GitCommit { readonly refType: GitStashReference['refType']; readonly stashName: string; diff --git a/src/plus/github/githubGitProvider.ts b/src/plus/github/githubGitProvider.ts index 5d34fe2..6149e77 100644 --- a/src/plus/github/githubGitProvider.ts +++ b/src/plus/github/githubGitProvider.ts @@ -41,7 +41,7 @@ import type { GitBlame, GitBlameAuthor, GitBlameLine, GitBlameLines } from '../. import type { BranchSortOptions } from '../../git/models/branch'; import { getBranchId, GitBranch, sortBranches } from '../../git/models/branch'; import type { GitCommitLine } from '../../git/models/commit'; -import { GitCommit, GitCommitIdentity } from '../../git/models/commit'; +import { getChangedFilesCount, GitCommit, GitCommitIdentity } from '../../git/models/commit'; import { GitContributor } from '../../git/models/contributor'; import type { GitDiff, GitDiffFilter, GitDiffHunkLine, GitDiffShortStat } from '../../git/models/diff'; import type { GitFile } from '../../git/models/file'; @@ -867,10 +867,7 @@ export class GitHubGitProvider implements GitProvider, Disposable { const { stats } = commit; - const changedFiles = - typeof stats.changedFiles === 'number' - ? stats.changedFiles - : stats.changedFiles.added + stats.changedFiles.changed + stats.changedFiles.deleted; + const changedFiles = getChangedFilesCount(stats.changedFiles); return { additions: stats.additions, deletions: stats.deletions, changedFiles: changedFiles }; } diff --git a/src/plus/webviews/timeline/timelineWebview.ts b/src/plus/webviews/timeline/timelineWebview.ts index 431887b..bd77ea6 100644 --- a/src/plus/webviews/timeline/timelineWebview.ts +++ b/src/plus/webviews/timeline/timelineWebview.ts @@ -7,6 +7,7 @@ import { Commands, ContextKeys } from '../../../constants'; import type { Container } from '../../../container'; import { PlusFeatures } from '../../../features'; import { GitUri } from '../../../git/gitUri'; +import { getChangedFilesCount } from '../../../git/models/commit'; import type { RepositoryChangeEvent } from '../../../git/models/repository'; import { RepositoryChange, RepositoryChangeComparisonMode } from '../../../git/models/repository'; import { registerCommand } from '../../../system/command'; @@ -234,7 +235,10 @@ export class TimelineWebview extends WebviewBase { } let queryRequiredCommits = [ - ...filter(log.commits.values(), c => c.file?.stats == null && c.stats?.changedFiles !== 1), + ...filter( + log.commits.values(), + c => c.file?.stats == null && getChangedFilesCount(c.stats?.changedFiles) !== 1, + ), ]; if (queryRequiredCommits.length !== 0) { @@ -259,7 +263,9 @@ export class TimelineWebview extends WebviewBase { const dataset: Commit[] = []; for (const commit of log.commits.values()) { - const stats = commit.file?.stats ?? (commit.stats?.changedFiles === 1 ? commit.stats : undefined); + const stats = + commit.file?.stats ?? + (getChangedFilesCount(commit.stats?.changedFiles) === 1 ? commit.stats : undefined); dataset.push({ author: commit.author.name === 'You' ? name : commit.author.name, additions: stats?.additions, diff --git a/src/plus/webviews/timeline/timelineWebviewView.ts b/src/plus/webviews/timeline/timelineWebviewView.ts index 510f700..5e5ee51 100644 --- a/src/plus/webviews/timeline/timelineWebviewView.ts +++ b/src/plus/webviews/timeline/timelineWebviewView.ts @@ -8,6 +8,7 @@ import type { FileSelectedEvent } from '../../../eventBus'; import { PlusFeatures } from '../../../features'; import type { RepositoriesChangeEvent } from '../../../git/gitProviderService'; import { GitUri } from '../../../git/gitUri'; +import { getChangedFilesCount } from '../../../git/models/commit'; import type { RepositoryChangeEvent } from '../../../git/models/repository'; import { RepositoryChange, RepositoryChangeComparisonMode } from '../../../git/models/repository'; import { registerCommand } from '../../../system/command'; @@ -279,7 +280,10 @@ export class TimelineWebviewView extends WebviewViewBase { } let queryRequiredCommits = [ - ...filter(log.commits.values(), c => c.file?.stats == null && c.stats?.changedFiles !== 1), + ...filter( + log.commits.values(), + c => c.file?.stats == null && getChangedFilesCount(c.stats?.changedFiles) !== 1, + ), ]; if (queryRequiredCommits.length !== 0) { @@ -304,7 +308,9 @@ export class TimelineWebviewView extends WebviewViewBase { const dataset: Commit[] = []; for (const commit of log.commits.values()) { - const stats = commit.file?.stats ?? (commit.stats?.changedFiles === 1 ? commit.stats : undefined); + const stats = + commit.file?.stats ?? + (getChangedFilesCount(commit.stats?.changedFiles) === 1 ? commit.stats : undefined); dataset.push({ author: commit.author.name === 'You' ? name : commit.author.name, additions: stats?.additions,