diff --git a/extensions/git/package.json b/extensions/git/package.json index 9743287dfb9..937f9591b05 100644 --- a/extensions/git/package.json +++ b/extensions/git/package.json @@ -567,7 +567,7 @@ "title": "%command.pull%", "icon": "$(repo-pull)", "category": "Git", - "enablement": "!operationInProgress" + "enablement": "!operationInProgress && scmCurrentHistoryItemRefInFilter && scmCurrentHistoryItemRefHasRemote" }, { "command": "git.push", @@ -616,7 +616,7 @@ "title": "%command.push%", "icon": "$(repo-push)", "category": "Git", - "enablement": "!operationInProgress" + "enablement": "!operationInProgress && scmCurrentHistoryItemRefInFilter && scmCurrentHistoryItemRefHasRemote" }, { "command": "git.cherryPick", @@ -1968,8 +1968,23 @@ "scm/history/title": [ { "command": "git.fetchAll", - "group": "navigation@999", + "group": "navigation@900", "when": "scmProvider == git" + }, + { + "command": "git.pullRef", + "group": "navigation@901", + "when": "scmProvider == git" + }, + { + "command": "git.pushRef", + "when": "scmProvider == git && scmCurrentHistoryItemRefHasRemote", + "group": "navigation@902" + }, + { + "command": "git.publish", + "when": "scmProvider == git && !scmCurrentHistoryItemRefHasRemote", + "group": "navigation@903" } ], "scm/historyItem/context": [ diff --git a/src/vs/workbench/contrib/scm/browser/scmHistoryViewPane.ts b/src/vs/workbench/contrib/scm/browser/scmHistoryViewPane.ts index b78355be9e6..8b786a6d407 100644 --- a/src/vs/workbench/contrib/scm/browser/scmHistoryViewPane.ts +++ b/src/vs/workbench/contrib/scm/browser/scmHistoryViewPane.ts @@ -61,7 +61,6 @@ import { compare } from '../../../../base/common/strings.js'; import { IClipboardService } from '../../../../platform/clipboard/common/clipboardService.js'; import { getDefaultHoverDelegate } from '../../../../base/browser/ui/hover/hoverDelegateFactory.js'; import { IStorageService, StorageScope, StorageTarget } from '../../../../platform/storage/common/storage.js'; -import { INotificationService } from '../../../../platform/notification/common/notification.js'; import { IExtensionService } from '../../../services/extensions/common/extensions.js'; import { groupBy as groupBy2 } from '../../../../base/common/collections.js'; @@ -196,7 +195,9 @@ registerAction2(class extends ViewAction { title: localize('goToCurrentHistoryItem', "Go to Current History Item"), icon: Codicon.target, viewId: HISTORY_VIEW_PANE_ID, - precondition: ContextKeys.SCMHistoryItemCount.notEqualsTo(0), + precondition: ContextKeyExpr.and( + ContextKeys.SCMHistoryItemCount.notEqualsTo(0), + ContextKeys.SCMCurrentHistoryItemRefInFilter.isEqualTo(true)), f1: false, menu: { id: MenuId.SCMHistoryTitle, @@ -1205,12 +1206,13 @@ export class SCMHistoryViewPane extends ViewPane { private readonly _updateChildrenThrottler = new Throttler(); private readonly _scmProviderCtx: IContextKey; + private readonly _scmCurrentHistoryItemRefHasRemote: IContextKey; + private readonly _scmCurrentHistoryItemRefInFilter: IContextKey; constructor( options: IViewPaneOptions, @ICommandService private readonly _commandService: ICommandService, @IInstantiationService private readonly _instantiationService: IInstantiationService, - @INotificationService private readonly _notificationService: INotificationService, @IProgressService private readonly _progressService: IProgressService, @IConfigurationService configurationService: IConfigurationService, @IContextMenuService contextMenuService: IContextMenuService, @@ -1230,6 +1232,8 @@ export class SCMHistoryViewPane extends ViewPane { }, keybindingService, contextMenuService, configurationService, contextKeyService, viewDescriptorService, instantiationService, openerService, themeService, telemetryService, hoverService); this._scmProviderCtx = ContextKeys.SCMProvider.bindTo(this.scopedContextKeyService); + this._scmCurrentHistoryItemRefHasRemote = ContextKeys.SCMCurrentHistoryItemRefHasRemote.bindTo(this.scopedContextKeyService); + this._scmCurrentHistoryItemRefInFilter = ContextKeys.SCMCurrentHistoryItemRefInFilter.bindTo(this.scopedContextKeyService); this._actionRunner = this.instantiationService.createInstance(SCMHistoryViewPaneActionRunner); this._register(this._actionRunner); @@ -1311,15 +1315,15 @@ export class SCMHistoryViewPane extends ViewPane { return; } - // Update context - this._scmProviderCtx.set(repository.provider.contextValue); - // HistoryItemId changed (checkout) const historyItemRefId = derived(reader => { return historyProvider.historyItemRef.read(reader)?.id; }); - store.add(runOnChange(historyItemRefId, () => { + store.add(runOnChange(historyItemRefId, historyItemRefIdValue => { this.refresh(); + + // Update context key (needs to be done after the refresh call) + this._scmCurrentHistoryItemRefInFilter.set(this._isCurrentHistoryItemInFilter(historyItemRefIdValue)); })); // HistoryItemRefs changed @@ -1344,8 +1348,20 @@ export class SCMHistoryViewPane extends ViewPane { // HistoryItemRefs filter changed store.add(runOnChange(this._treeViewModel.onDidChangeHistoryItemsFilter, () => { this.refresh(); + + // Update context key (needs to be done after the refresh call) + this._scmCurrentHistoryItemRefInFilter.set(this._isCurrentHistoryItemInFilter(historyItemRefId.get())); })); + // HistoryItemRemoteRef changed + store.add(autorun(reader => { + this._scmCurrentHistoryItemRefHasRemote.set(!!historyProvider.historyItemRemoteRef.read(reader)); + })); + + // Update context + this._scmProviderCtx.set(repository.provider.contextValue); + this._scmCurrentHistoryItemRefInFilter.set(this._isCurrentHistoryItemInFilter(historyItemRefId.get())); + // We skip refreshing the graph on the first execution of the autorun // since the graph for the first repository is rendered when the tree // input is set. @@ -1438,16 +1454,11 @@ export class SCMHistoryViewPane extends ViewPane { const repository = this._treeViewModel.repository.get(); const historyProvider = repository?.provider.historyProvider.get(); const historyItemRef = historyProvider?.historyItemRef.get(); - const historyItemFilter = this._treeViewModel.getHistoryItemsFilter(); - - if (!repository || !historyItemRef?.revision || !historyItemFilter) { + if (!repository || !historyItemRef?.id || !historyItemRef?.revision) { return; } - // Filter set to `all`, `auto` or it contains the current history item - if (Array.isArray(historyItemFilter) && - !historyItemFilter.find(ref => ref.id === historyItemRef.id)) { - this._notificationService.info(localize('scmGraphViewRevealCurrentHistoryItem', "The current history item is not present in the source control graph. Please use the history item references picker to expand the set of history items in the graph.")); + if (this._isCurrentHistoryItemInFilter(historyItemRef.id)) { return; } @@ -1513,6 +1524,19 @@ export class SCMHistoryViewPane extends ViewPane { this._tree.onContextMenu(this._onContextMenu, this, this._store); } + private _isCurrentHistoryItemInFilter(historyItemRefId: string | undefined): boolean { + if (!historyItemRefId) { + return false; + } + + const historyItemFilter = this._treeViewModel.getHistoryItemsFilter(); + if (historyItemFilter === 'all' || historyItemFilter === 'auto') { + return true; + } + + return Array.isArray(historyItemFilter) && !!historyItemFilter.find(ref => ref.id === historyItemRefId); + } + private async _onDidOpen(e: IOpenEvent): Promise { if (!e.element) { return; diff --git a/src/vs/workbench/contrib/scm/browser/scmViewPane.ts b/src/vs/workbench/contrib/scm/browser/scmViewPane.ts index 74b108d5488..0f397632c2e 100644 --- a/src/vs/workbench/contrib/scm/browser/scmViewPane.ts +++ b/src/vs/workbench/contrib/scm/browser/scmViewPane.ts @@ -964,6 +964,8 @@ export const ContextKeys = { SCMProviderRootUri: new RawContextKey('scmProviderRootUri', undefined), SCMProviderHasRootUri: new RawContextKey('scmProviderHasRootUri', undefined), SCMHistoryItemCount: new RawContextKey('scmHistoryItemCount', 0), + SCMCurrentHistoryItemRefHasRemote: new RawContextKey('scmCurrentHistoryItemRefHasRemote', false), + SCMCurrentHistoryItemRefInFilter: new RawContextKey('scmCurrentHistoryItemRefInFilter', false), RepositoryCount: new RawContextKey('scmRepositoryCount', 0), RepositoryVisibilityCount: new RawContextKey('scmRepositoryVisibleCount', 0), RepositoryVisibility(repository: ISCMRepository) {