From 4d07969cf9e5cea9bd13635957a700cae0e61464 Mon Sep 17 00:00:00 2001 From: Fabian Lauer Date: Thu, 11 Aug 2016 23:11:02 +0200 Subject: [PATCH 1/2] ignore untracked in git change count badge --- .../git/browser/gitWorkbenchContributions.ts | 24 +++++++++++++++---- src/vs/workbench/parts/git/common/git.ts | 1 + 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/vs/workbench/parts/git/browser/gitWorkbenchContributions.ts b/src/vs/workbench/parts/git/browser/gitWorkbenchContributions.ts index 15c7b694520..8d58581e885 100644 --- a/src/vs/workbench/parts/git/browser/gitWorkbenchContributions.ts +++ b/src/vs/workbench/parts/git/browser/gitWorkbenchContributions.ts @@ -26,6 +26,7 @@ import output = require('vs/workbench/parts/output/common/output'); import {SyncActionDescriptor} from 'vs/platform/actions/common/actions'; import {EditorBrowserRegistry} from 'vs/editor/browser/editorBrowserExtensions'; import confregistry = require('vs/platform/configuration/common/configurationRegistry'); +import {IConfigurationService} from 'vs/platform/configuration/common/configuration'; import quickopen = require('vs/workbench/browser/quickopen'); import editorcontrib = require('vs/workbench/parts/git/browser/gitEditorContributions'); import {IActivityService, ProgressBadge, NumberBadge} from 'vs/workbench/services/activity/common/activityService'; @@ -52,6 +53,7 @@ export class StatusUpdater implements ext.IWorkbenchContribution private eventService: IEventService; private activityService:IActivityService; private messageService:IMessageService; + private configurationService:IConfigurationService; private progressBadgeDelayer: async.Delayer; private toDispose: lifecycle.IDisposable[]; @@ -59,12 +61,14 @@ export class StatusUpdater implements ext.IWorkbenchContribution @IGitService gitService: IGitService, @IEventService eventService: IEventService, @IActivityService activityService: IActivityService, - @IMessageService messageService: IMessageService + @IMessageService messageService: IMessageService, + @IConfigurationService configurationService: IConfigurationService ) { this.gitService = gitService; this.eventService = eventService; this.activityService = activityService; this.messageService = messageService; + this.configurationService = configurationService; this.progressBadgeDelayer = new async.Delayer(200); @@ -86,9 +90,21 @@ export class StatusUpdater implements ext.IWorkbenchContribution } private showChangesBadge(): void { - var count = this.gitService.getModel().getStatus().getGroups().map((g1: git.IStatusGroup) => { - return g1.all().length; - }).reduce((a, b) => a + b, 0); + const config = this.configurationService.getConfiguration('git'); + + // only use the filter version of the map callback if filtering by file status is really necessary + var mapper = (g1: git.IStatusGroup) => { + return g1.all().filter((f1: git.IFileStatus) => { + return f1.getStatus() !== git.Status.UNTRACKED; + }).length; + }; + + // no need to filter by file status if we count both tracked and untracked files + if (config.countUntracked) { + mapper = (g1: git.IStatusGroup) => g1.all().length; + } + + var count = this.gitService.getModel().getStatus().getGroups().map(mapper).reduce((a, b) => a + b, 0); var badge = new NumberBadge(count, (num)=>{ return nls.localize('gitPendingChangesBadge', '{0} pending changes', num); }); diff --git a/src/vs/workbench/parts/git/common/git.ts b/src/vs/workbench/parts/git/common/git.ts index 3bb7bfb6019..5a218684180 100644 --- a/src/vs/workbench/parts/git/common/git.ts +++ b/src/vs/workbench/parts/git/common/git.ts @@ -235,6 +235,7 @@ export interface IGitConfiguration { enableLongCommitWarning: boolean; allowLargeRepositories: boolean; confirmSync: boolean; + countUntracked: boolean; } // Service interfaces From 88271cedb63a6e19ea30a6daa39a2bcb229e14bf Mon Sep 17 00:00:00 2001 From: Fabian Lauer Date: Thu, 11 Aug 2016 23:12:03 +0200 Subject: [PATCH 2/2] add git setting 'git.countUntracked' --- .../workbench/parts/git/browser/gitWorkbenchContributions.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/vs/workbench/parts/git/browser/gitWorkbenchContributions.ts b/src/vs/workbench/parts/git/browser/gitWorkbenchContributions.ts index 8d58581e885..48355bed0f7 100644 --- a/src/vs/workbench/parts/git/browser/gitWorkbenchContributions.ts +++ b/src/vs/workbench/parts/git/browser/gitWorkbenchContributions.ts @@ -563,6 +563,11 @@ export function registerContributions(): void { type: 'boolean', description: nls.localize('confirmSync', "Confirm before synchronizing git repositories."), default: false + }, + 'git.countUntracked': { + type: 'boolean', + description: nls.localize('countUntracked', "Count untracked files in the changes badge."), + default: true } } });