diff --git a/extensions/git/package.json b/extensions/git/package.json index 96ece71a59f..faa5715d64c 100644 --- a/extensions/git/package.json +++ b/extensions/git/package.json @@ -1021,7 +1021,7 @@ "command": "git.graph.compareWithMergeBase", "title": "%command.graphCompareWithMergeBase%", "category": "Git", - "enablement": "!operationInProgress && git.currentHistoryItemHasMergeBase" + "enablement": "!operationInProgress && scmCurrentHistoryItemRefHasBase" } ], "continueEditSession": [ @@ -2270,11 +2270,6 @@ "command": "git.graph.openOutgoingChanges", "when": "scmProvider == git", "group": "1_changes@2" - }, - { - "command": "git.graph.compareWithMergeBase", - "when": "scmProvider == git", - "group": "2_compare@1" } ], "scm/historyItem/context": [ @@ -2303,6 +2298,11 @@ "when": "scmProvider == git", "group": "5_compare@1" }, + { + "command": "git.graph.compareWithMergeBase", + "when": "scmProvider == git && scmHistoryItemHasCurrentHistoryItemRef", + "group": "5_compare@2" + }, { "command": "git.copyCommitId", "when": "scmProvider == git && !listMultiSelection", diff --git a/extensions/git/src/historyProvider.ts b/extensions/git/src/historyProvider.ts index 1ed44906ab3..5c323c6acd6 100644 --- a/extensions/git/src/historyProvider.ts +++ b/extensions/git/src/historyProvider.ts @@ -192,7 +192,6 @@ export class GitHistoryProvider implements SourceControlHistoryProvider, FileDec if (this._HEAD?.behind !== this.repository.HEAD?.behind) { commands.executeCommand('setContext', 'git.currentHistoryItemIsBehind', (this.repository.HEAD?.behind ?? 0) > 0); } - commands.executeCommand('setContext', 'git.currentHistoryItemHasMergeBase', this._currentHistoryItemBaseRef !== undefined); this._HEAD = this.repository.HEAD; diff --git a/src/vs/workbench/contrib/scm/browser/scmHistoryViewPane.ts b/src/vs/workbench/contrib/scm/browser/scmHistoryViewPane.ts index 21a3f1e9ae0..848f02a5185 100644 --- a/src/vs/workbench/contrib/scm/browser/scmHistoryViewPane.ts +++ b/src/vs/workbench/contrib/scm/browser/scmHistoryViewPane.ts @@ -1531,6 +1531,7 @@ export class SCMHistoryViewPane extends ViewPane { private readonly _scmProviderCtx: IContextKey; private readonly _scmCurrentHistoryItemRefHasRemote: IContextKey; + private readonly _scmCurrentHistoryItemRefHasBase: IContextKey; private readonly _scmCurrentHistoryItemRefInFilter: IContextKey; private readonly _contextMenuDisposables = new MutableDisposable(); @@ -1559,6 +1560,7 @@ export class SCMHistoryViewPane extends ViewPane { this._scmProviderCtx = ContextKeys.SCMProvider.bindTo(this.scopedContextKeyService); this._scmCurrentHistoryItemRefHasRemote = ContextKeys.SCMCurrentHistoryItemRefHasRemote.bindTo(this.scopedContextKeyService); + this._scmCurrentHistoryItemRefHasBase = ContextKeys.SCMCurrentHistoryItemRefHasBase.bindTo(this.scopedContextKeyService); this._scmCurrentHistoryItemRefInFilter = ContextKeys.SCMCurrentHistoryItemRefInFilter.bindTo(this.scopedContextKeyService); this._actionRunner = this.instantiationService.createInstance(SCMHistoryViewPaneActionRunner); @@ -1685,6 +1687,11 @@ export class SCMHistoryViewPane extends ViewPane { this._scmCurrentHistoryItemRefHasRemote.set(!!historyProvider.historyItemRemoteRef.read(reader)); })); + // HistoryItemBaseRef changed + reader.store.add(autorun(reader => { + this._scmCurrentHistoryItemRefHasBase.set(!!historyProvider.historyItemBaseRef.read(reader)); + })); + // ViewMode changed reader.store.add(runOnChange(this._treeViewModel.viewMode, async () => { await this._updateChildren(); @@ -1958,6 +1965,10 @@ export class SCMHistoryViewPane extends ViewPane { // HistoryItem this._contextMenuDisposables.value = new DisposableStore(); + const historyProvider = element.repository.provider.historyProvider.get(); + const historyItemRef = historyProvider?.historyItemRef.get(); + const historyItem = element.historyItemViewModel.historyItem; + const historyItemRefMenuItems = MenuRegistry.getMenuItems(MenuId.SCMHistoryItemRefContext).filter(item => isIMenuItem(item)); // If there are any history item references we have to add a submenu item for each orignal action, @@ -2020,9 +2031,13 @@ export class SCMHistoryViewPane extends ViewPane { } } + const contextKeyService = this.scopedContextKeyService.createOverlay([ + ['scmHistoryItemHasCurrentHistoryItemRef', historyItem.references?.find(ref => ref.id === historyItemRef?.id) !== undefined] + ]); + const menuActions = this._menuService.getMenuActions( MenuId.SCMHistoryItemContext, - this.scopedContextKeyService, { + contextKeyService, { arg: element.repository.provider, shouldForwardArgs: true }).filter(group => group[0] !== 'inline'); diff --git a/src/vs/workbench/contrib/scm/browser/scmViewPane.ts b/src/vs/workbench/contrib/scm/browser/scmViewPane.ts index 7d2cac7cb02..1b0117826d3 100644 --- a/src/vs/workbench/contrib/scm/browser/scmViewPane.ts +++ b/src/vs/workbench/contrib/scm/browser/scmViewPane.ts @@ -986,6 +986,7 @@ export const ContextKeys = { SCMHistoryItemCount: new RawContextKey('scmHistoryItemCount', 0), SCMHistoryViewMode: new RawContextKey('scmHistoryViewMode', ViewMode.List), SCMCurrentHistoryItemRefHasRemote: new RawContextKey('scmCurrentHistoryItemRefHasRemote', false), + SCMCurrentHistoryItemRefHasBase: new RawContextKey('scmCurrentHistoryItemRefHasBase', false), SCMCurrentHistoryItemRefInFilter: new RawContextKey('scmCurrentHistoryItemRefInFilter', false), RepositoryCount: new RawContextKey('scmRepositoryCount', 0), RepositoryVisibilityCount: new RawContextKey('scmRepositoryVisibleCount', 0),