From d7ef13d09bfead6ee7e6e0b1a258d00cf5f6ea23 Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Mon, 19 Dec 2022 22:43:43 -0500 Subject: [PATCH] Fixes #2301 handles new view/title callback change --- CHANGELOG.md | 1 + package.json | 48 +++++++++++- src/commands/searchCommits.ts | 8 +- src/views/nodes/contributorNode.ts | 4 + src/views/nodes/contributorsNode.ts | 4 + src/views/nodes/viewNode.ts | 8 ++ src/views/searchAndCompareView.ts | 2 +- src/views/viewCommands.ts | 143 ++++++++++++++++++++---------------- 8 files changed, 147 insertions(+), 71 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4c2bce3..b81fbcf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p ### Fixed +- Fixes [#2301](https://github.com/gitkraken/vscode-gitlens/issues/2301) - Create Worktree button doesn't work in certain cases - Fixes [#2318](https://github.com/gitkraken/vscode-gitlens/issues/2318) - GitLens need to login again after VS Code insiders upgrade every day - Fixes [#2377](https://github.com/gitkraken/vscode-gitlens/issues/2377) - Missing Azure Devops Icon - Fixes [#2380](https://github.com/gitkraken/vscode-gitlens/issues/2380) - Autolink fails with curly braces diff --git a/package.json b/package.json index 0e17d9f..d832062 100644 --- a/package.json +++ b/package.json @@ -5406,12 +5406,24 @@ "icon": "$(person-add)" }, { + "command": "gitlens.views.title.applyStash", + "title": "Apply a Stash...", + "category": "GitLens", + "icon": "$(gitlens-stash-pop)" + }, + { "command": "gitlens.views.createWorktree", "title": "Create Worktree...", "category": "GitLens", "icon": "$(add)" }, { + "command": "gitlens.views.title.createWorktree", + "title": "Create Worktree...", + "category": "GitLens", + "icon": "$(add)" + }, + { "command": "gitlens.views.deleteWorktree", "title": "Delete Worktree...", "category": "GitLens", @@ -5446,6 +5458,12 @@ "icon": "$(add)" }, { + "command": "gitlens.views.title.createBranch", + "title": "Create Branch...", + "category": "GitLens", + "icon": "$(add)" + }, + { "command": "gitlens.views.deleteBranch", "title": "Delete Branch...", "category": "GitLens", @@ -5463,6 +5481,12 @@ "icon": "$(add)" }, { + "command": "gitlens.views.title.createTag", + "title": "Create Tag...", + "category": "GitLens", + "icon": "$(add)" + }, + { "command": "gitlens.views.deleteTag", "title": "Delete Tag...", "category": "GitLens", @@ -7767,10 +7791,18 @@ "when": "false" }, { + "command": "gitlens.views.title.applyStash", + "when": "false" + }, + { "command": "gitlens.views.createWorktree", "when": "false" }, { + "command": "gitlens.views.title.createWorktree", + "when": "false" + }, + { "command": "gitlens.views.deleteWorktree", "when": "false" }, @@ -7791,6 +7823,10 @@ "when": "false" }, { + "command": "gitlens.views.title.createBranch", + "when": "false" + }, + { "command": "gitlens.views.deleteBranch", "when": "false" }, @@ -7847,6 +7883,10 @@ "when": "false" }, { + "command": "gitlens.views.title.createTag", + "when": "false" + }, + { "command": "gitlens.views.deleteTag", "when": "false" }, @@ -9153,7 +9193,7 @@ "group": "navigation@10" }, { - "command": "gitlens.views.createBranch", + "command": "gitlens.views.title.createBranch", "when": "!gitlens:readonly && !gitlens:untrusted && !gitlens:hasVirtualFolders && view =~ /gitlens\\.views\\.branches\\b/", "group": "navigation@11" }, @@ -9648,7 +9688,7 @@ "group": "navigation@10" }, { - "command": "gitlens.stashApply", + "command": "gitlens.views.title.applyStash", "when": "!gitlens:readonly && !gitlens:untrusted && !gitlens:hasVirtualFolders && view =~ /^gitlens\\.views\\.stashes/", "group": "navigation@11" }, @@ -9673,7 +9713,7 @@ "group": "navigation@99" }, { - "command": "gitlens.views.createTag", + "command": "gitlens.views.title.createTag", "when": "!gitlens:readonly && !gitlens:untrusted && !gitlens:hasVirtualFolders && view =~ /gitlens\\.views\\.tags\\b/", "group": "navigation@10" }, @@ -9728,7 +9768,7 @@ "group": "navigation@99" }, { - "command": "gitlens.views.createWorktree", + "command": "gitlens.views.title.createWorktree", "when": "view =~ /^gitlens\\.views\\.worktrees/", "group": "navigation@10" }, diff --git a/src/commands/searchCommits.ts b/src/commands/searchCommits.ts index c1aee38..0432325 100644 --- a/src/commands/searchCommits.ts +++ b/src/commands/searchCommits.ts @@ -25,7 +25,10 @@ export class SearchCommitsCommand extends Command { } protected override preExecute(context: CommandContext, args?: SearchCommitsCommandArgs) { - if (context.type === 'viewItem') { + if (context.command === Commands.SearchCommitsInView) { + args = { ...args }; + args.showResultsInSideBar = true; + } else if (context.type === 'viewItem') { args = { ...args }; args.showResultsInSideBar = true; @@ -38,9 +41,6 @@ export class SearchCommitsCommand extends Command { if (isCommandContextViewNodeHasRepository(context)) { args.repoPath = context.node.repo.path; } - } else if (context.command === Commands.SearchCommitsInView) { - args = { ...args }; - args.showResultsInSideBar = true; } return this.execute(args); diff --git a/src/views/nodes/contributorNode.ts b/src/views/nodes/contributorNode.ts index dfffaa1..939bb0f 100644 --- a/src/views/nodes/contributorNode.ts +++ b/src/views/nodes/contributorNode.ts @@ -57,6 +57,10 @@ export class ContributorNode extends ViewNode { const log = await this.getLog(); if (log == null) return [new MessageNode(this.view, this, 'No commits could be found.')]; diff --git a/src/views/nodes/contributorsNode.ts b/src/views/nodes/contributorsNode.ts index a1cc165..5823af9 100644 --- a/src/views/nodes/contributorsNode.ts +++ b/src/views/nodes/contributorsNode.ts @@ -36,6 +36,10 @@ export class ContributorsNode extends ViewNode { if (this._children == null) { const all = configuration.get('views.contributors.showAllBranches'); diff --git a/src/views/nodes/viewNode.ts b/src/views/nodes/viewNode.ts index 682f8ae..96a4117 100644 --- a/src/views/nodes/viewNode.ts +++ b/src/views/nodes/viewNode.ts @@ -627,6 +627,14 @@ export function canEditNode(node: ViewNode): node is ViewNode & { edit(): void | return typeof (node as ViewNode & { edit(): void | Promise }).edit === 'function'; } +export function canGetNodeRepoPath(node?: ViewNode): node is ViewNode & { repoPath: string | undefined } { + return node != null && 'repoPath' in node && typeof node.repoPath === 'string'; +} + export function canViewDismissNode(view: View): view is View & { dismissNode(node: ViewNode): void } { return typeof (view as View & { dismissNode(node: ViewNode): void }).dismissNode === 'function'; } + +export function getNodeRepoPath(node?: ViewNode): string | undefined { + return canGetNodeRepoPath(node) ? node.repoPath : undefined; +} diff --git a/src/views/searchAndCompareView.ts b/src/views/searchAndCompareView.ts index 79a95de..3010533 100644 --- a/src/views/searchAndCompareView.ts +++ b/src/views/searchAndCompareView.ts @@ -295,7 +295,7 @@ export class SearchAndCompareView extends ViewBase this.selectForCompare()), registerViewCommand(this.getQualifiedCommand('compareWithSelected'), this.compareWithSelected, this), registerViewCommand( diff --git a/src/views/viewCommands.ts b/src/views/viewCommands.ts index 69216f9..14a7711 100644 --- a/src/views/viewCommands.ts +++ b/src/views/viewCommands.ts @@ -27,7 +27,7 @@ import { debug } from '../system/decorators/log'; import { sequentialize } from '../system/function'; import { OpenWorkspaceLocation } from '../system/utils'; import { runGitCommandInTerminal } from '../terminal'; -import { BranchesNode } from './nodes/branchesNode'; +import type { BranchesNode } from './nodes/branchesNode'; import { BranchNode } from './nodes/branchNode'; import { BranchTrackingStatusNode } from './nodes/branchTrackingStatusNode'; import { CommitFileNode } from './nodes/commitFileNode'; @@ -35,7 +35,6 @@ import { CommitNode } from './nodes/commitNode'; import type { PagerNode } from './nodes/common'; import { CompareBranchNode } from './nodes/compareBranchNode'; import { ContributorNode } from './nodes/contributorNode'; -import { ContributorsNode } from './nodes/contributorsNode'; import { FileHistoryNode } from './nodes/fileHistoryNode'; import { FileRevisionAsCommitNode } from './nodes/fileRevisionAsCommitNode'; import { FolderNode } from './nodes/folderNode'; @@ -43,7 +42,6 @@ import { LineHistoryNode } from './nodes/lineHistoryNode'; import { MergeConflictFileNode } from './nodes/mergeConflictFileNode'; import { PullRequestNode } from './nodes/pullRequestNode'; import { RemoteNode } from './nodes/remoteNode'; -import type { RemotesNode } from './nodes/remotesNode'; import { RepositoryNode } from './nodes/repositoryNode'; import { ResultsFileNode } from './nodes/resultsFileNode'; import { ResultsFilesNode } from './nodes/resultsFilesNode'; @@ -56,6 +54,7 @@ import { canClearNode, canEditNode, canViewDismissNode, + getNodeRepoPath, PageableViewNode, RepositoryFolderNode, ViewNode, @@ -199,7 +198,7 @@ export class ViewCommands { ); registerViewCommand('gitlens.views.addAuthors', this.addAuthors, this); - registerViewCommand('gitlens.views.addAuthor', this.addAuthors, this); + registerViewCommand('gitlens.views.addAuthor', this.addAuthor, this); registerViewCommand('gitlens.views.openChanges', this.openChanges, this); registerViewCommand('gitlens.views.openChangesWithWorking', this.openChangesWithWorking, this); @@ -214,10 +213,10 @@ export class ViewCommands { registerViewCommand('gitlens.views.highlightChanges', this.highlightChanges, this); registerViewCommand('gitlens.views.highlightRevisionChanges', this.highlightRevisionChanges, this); registerViewCommand('gitlens.views.restore', this.restore, this); - registerViewCommand('gitlens.views.switchToBranch', this.switch, this); registerViewCommand('gitlens.views.switchToAnotherBranch', this.switch, this); - registerViewCommand('gitlens.views.switchToCommit', this.switch, this); - registerViewCommand('gitlens.views.switchToTag', this.switch, this); + registerViewCommand('gitlens.views.switchToBranch', this.switchTo, this); + registerViewCommand('gitlens.views.switchToCommit', this.switchTo, this); + registerViewCommand('gitlens.views.switchToTag', this.switchTo, this); registerViewCommand('gitlens.views.addRemote', this.addRemote, this); registerViewCommand('gitlens.views.pruneRemote', this.pruneRemote, this); @@ -247,10 +246,16 @@ export class ViewCommands { ); registerViewCommand('gitlens.views.cherryPick', this.cherryPick, this, ViewCommandMultiSelectMode.Custom); + + registerViewCommand('gitlens.views.title.createBranch', () => this.createBranch()); registerViewCommand('gitlens.views.createBranch', this.createBranch, this); registerViewCommand('gitlens.views.deleteBranch', this.deleteBranch, this); registerViewCommand('gitlens.views.renameBranch', this.renameBranch, this); + + registerViewCommand('gitlens.views.title.applyStash', () => this.applyStash()); registerViewCommand('gitlens.views.deleteStash', this.deleteStash, this, ViewCommandMultiSelectMode.Custom); + + registerViewCommand('gitlens.views.title.createTag', () => this.createTag()); registerViewCommand('gitlens.views.createTag', this.createTag, this); registerViewCommand('gitlens.views.deleteTag', this.deleteTag, this); @@ -271,6 +276,7 @@ export class ViewCommands { registerViewCommand('gitlens.views.createPullRequest', this.createPullRequest, this); registerViewCommand('gitlens.views.openPullRequest', this.openPullRequest, this); + registerViewCommand('gitlens.views.title.createWorktree', () => this.createWorktree()); registerViewCommand('gitlens.views.createWorktree', this.createWorktree, this); registerViewCommand('gitlens.views.deleteWorktree', this.deleteWorktree, this); registerViewCommand('gitlens.views.openWorktree', this.openWorktree, this); @@ -283,20 +289,25 @@ export class ViewCommands { } @debug() - private addAuthors(node?: ContributorNode | ContributorsNode) { - if (node != null && !(node instanceof ContributorNode) && !(node instanceof ContributorsNode)) { - return Promise.resolve(); + private addAuthors(node?: ViewNode) { + return GitActions.Contributor.addAuthors(getNodeRepoPath(node)); + } + + @debug() + private addAuthor(node?: ContributorNode) { + if (node instanceof ContributorNode) { + return GitActions.Contributor.addAuthors( + node.repoPath, + node.contributor.current ? undefined : node.contributor, + ); } - return GitActions.Contributor.addAuthors( - node?.uri.repoPath, - node instanceof ContributorNode ? node.contributor : undefined, - ); + return Promise.resolve(); } @debug() - private addRemote(node?: RemotesNode) { - return GitActions.Remote.add(node?.repoPath); + private addRemote(node?: ViewNode) { + return GitActions.Remote.add(getNodeRepoPath(node)); } @debug() @@ -317,6 +328,11 @@ export class ViewCommands { } @debug() + private applyStash() { + return GitActions.Stash.apply(); + } + + @debug() private browseRepoAtRevision(node: ViewRefNode, options?: { before?: boolean; openInNewWindow?: boolean }) { if (!(node instanceof ViewRefNode)) return Promise.resolve(); @@ -365,37 +381,6 @@ export class ViewCommands { } @debug() - private async createWorktree(node?: BranchNode | WorktreesNode) { - if (node instanceof WorktreesNode) { - node = undefined; - } - if (node != null && !(node instanceof BranchNode)) return undefined; - - return GitActions.Worktree.create(node?.repoPath, undefined, node?.ref); - } - - @debug() - private openWorktree(node: WorktreeNode, options?: { location?: OpenWorkspaceLocation }) { - if (!(node instanceof WorktreeNode)) return undefined; - - return GitActions.Worktree.open(node.worktree, options); - } - - @debug() - private revealWorktreeInExplorer(node: WorktreeNode) { - if (!(node instanceof WorktreeNode)) return undefined; - - return GitActions.Worktree.revealInFileExplorer(node.worktree); - } - - @debug() - private async deleteWorktree(node: WorktreeNode) { - if (!(node instanceof WorktreeNode)) return undefined; - - return GitActions.Worktree.remove(node.repoPath, node.worktree.uri); - } - - @debug() private async createPullRequest(node: BranchNode | BranchTrackingStatusNode) { if (!(node instanceof BranchNode) && !(node instanceof BranchTrackingStatusNode)) { return Promise.resolve(); @@ -446,6 +431,16 @@ export class ViewCommands { } @debug() + private async createWorktree(node?: BranchNode | WorktreesNode) { + if (node instanceof WorktreesNode) { + node = undefined; + } + if (node != null && !(node instanceof BranchNode)) return undefined; + + return GitActions.Worktree.create(node?.repoPath, undefined, node?.ref); + } + + @debug() private deleteBranch(node: BranchNode) { if (!(node instanceof BranchNode)) return Promise.resolve(); @@ -476,6 +471,13 @@ export class ViewCommands { } @debug() + private async deleteWorktree(node: WorktreeNode) { + if (!(node instanceof WorktreeNode)) return undefined; + + return GitActions.Worktree.remove(node.repoPath, node.worktree.uri); + } + + @debug() private fetch(node: RemoteNode | RepositoryNode | RepositoryFolderNode | BranchNode | BranchTrackingStatusNode) { if (node instanceof RepositoryNode || node instanceof RepositoryFolderNode) return GitActions.fetch(node.repo); if (node instanceof RemoteNode) return GitActions.Remote.fetch(node.remote.repoPath, node.remote.name); @@ -536,10 +538,10 @@ export class ViewCommands { } @debug() - private pushToCommit(node: CommitNode | FileRevisionAsCommitNode) { - if (!(node instanceof CommitNode) && !(node instanceof FileRevisionAsCommitNode)) return Promise.resolve(); + private openInTerminal(node: RepositoryNode | RepositoryFolderNode) { + if (!(node instanceof RepositoryNode) && !(node instanceof RepositoryFolderNode)) return Promise.resolve(); - return GitActions.push(node.repoPath, false, node.commit); + return executeCoreCommand(CoreCommands.OpenInTerminal, Uri.file(node.repo.path)); } @debug() @@ -561,10 +563,10 @@ export class ViewCommands { } @debug() - private openInTerminal(node: RepositoryNode | RepositoryFolderNode) { - if (!(node instanceof RepositoryNode) && !(node instanceof RepositoryFolderNode)) return Promise.resolve(); + private openWorktree(node: WorktreeNode, options?: { location?: OpenWorkspaceLocation }) { + if (!(node instanceof WorktreeNode)) return undefined; - return executeCoreCommand(CoreCommands.OpenInTerminal, Uri.file(node.repo.path)); + return GitActions.Worktree.open(node.worktree, options); } @debug() @@ -631,6 +633,13 @@ export class ViewCommands { } @debug() + private pushToCommit(node: CommitNode | FileRevisionAsCommitNode) { + if (!(node instanceof CommitNode) && !(node instanceof FileRevisionAsCommitNode)) return Promise.resolve(); + + return GitActions.push(node.repoPath, false, node.commit); + } + + @debug() private rebase(node: BranchNode | CommitNode | FileRevisionAsCommitNode | TagNode) { if ( !(node instanceof BranchNode) && @@ -697,6 +706,13 @@ export class ViewCommands { } @debug() + private revealWorktreeInExplorer(node: WorktreeNode) { + if (!(node instanceof WorktreeNode)) return undefined; + + return GitActions.Worktree.revealInFileExplorer(node.worktree); + } + + @debug() private revert(node: CommitNode | FileRevisionAsCommitNode) { if (!(node instanceof CommitNode) && !(node instanceof FileRevisionAsCommitNode)) return Promise.resolve(); @@ -758,17 +774,20 @@ export class ViewCommands { } @debug() - private switch(node?: ViewRefNode | BranchesNode) { - if (node == null) { - return GitActions.switchTo(this.container.git.highlander); - } + private switch(node?: ViewNode) { + return GitActions.switchTo(getNodeRepoPath(node)); + } - if (!(node instanceof ViewRefNode) && !(node instanceof BranchesNode)) return Promise.resolve(); + @debug() + private switchTo(node?: ViewNode) { + if (node instanceof ViewRefNode) { + return GitActions.switchTo( + node.repoPath, + node instanceof BranchNode && node.branch.current ? undefined : node.ref, + ); + } - return GitActions.switchTo( - node.repoPath, - node instanceof BranchesNode || (node instanceof BranchNode && node.branch.current) ? undefined : node.ref, - ); + return GitActions.switchTo(getNodeRepoPath(node)); } @debug()