diff --git a/src/vs/workbench/parts/git/browser/gitWorkbenchContributions.ts b/src/vs/workbench/parts/git/browser/gitWorkbenchContributions.ts index 15c7b694520afd164f72c5129390a230ea25b08d..48355bed0f7ebd924853cad16389525b04c7a1bb 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); }); @@ -547,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 } } }); diff --git a/src/vs/workbench/parts/git/common/git.ts b/src/vs/workbench/parts/git/common/git.ts index 6968a5f7b3d03b51690e707aa1ead2d37717848c..b00d9a1f3f17fcd302a7dd59f7d2f3c3117899e7 100644 --- a/src/vs/workbench/parts/git/common/git.ts +++ b/src/vs/workbench/parts/git/common/git.ts @@ -240,6 +240,7 @@ export interface IGitConfiguration { enableLongCommitWarning: boolean; allowLargeRepositories: boolean; confirmSync: boolean; + countUntracked: boolean; } // Service interfaces