From 577b47fc4a2a4a4b1c63282287a42ef4f067ddb2 Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Wed, 11 Sep 2019 02:32:15 -0400 Subject: [PATCH] Adds protection for null args in menu callbacks --- src/commands/annotations.ts | 8 +++++--- src/commands/closeUnchangedFiles.ts | 5 ++--- src/commands/copyMessageToClipboard.ts | 7 +++---- src/commands/copyShaToClipboard.ts | 7 +++---- src/commands/diffBranchWith.ts | 11 +++++++---- src/commands/diffDirectory.ts | 10 ++++++---- src/commands/diffLineWithPrevious.ts | 2 +- src/commands/diffLineWithWorking.ts | 2 +- src/commands/diffWithNext.ts | 5 +++-- src/commands/diffWithPrevious.ts | 5 +++-- src/commands/diffWithRef.ts | 2 +- src/commands/diffWithRevision.ts | 2 +- src/commands/diffWithWorking.ts | 2 +- src/commands/exploreRepoAtRevision.ts | 2 +- src/commands/externalDiff.ts | 14 ++++++-------- src/commands/inviteToLiveShare.ts | 6 +++--- src/commands/openBranchInRemote.ts | 8 ++++---- src/commands/openBranchesInRemote.ts | 6 +++--- src/commands/openChangedFiles.ts | 5 ++--- src/commands/openCommitInRemote.ts | 7 +++++-- src/commands/openFileRevision.ts | 2 +- src/commands/openFileRevisionFrom.ts | 4 +++- src/commands/openInRemote.ts | 4 ++-- src/commands/openRepoInRemote.ts | 6 +++--- src/commands/openRevisionFile.ts | 2 +- src/commands/openWorkingFile.ts | 2 +- src/commands/searchCommits.ts | 6 ++++-- src/commands/showQuickBranchHistory.ts | 2 +- src/commands/showQuickCommitDetails.ts | 4 ++-- src/commands/showQuickCommitFileDetails.ts | 7 ++++--- src/commands/showQuickCurrentBranchHistory.ts | 4 ++-- src/commands/showQuickFileHistory.ts | 8 ++++---- src/commands/showQuickRepoStatus.ts | 4 ++-- src/commands/showQuickStashList.ts | 6 +++--- src/commands/stashDelete.ts | 6 ++++-- src/commands/stashSave.ts | 6 ++++-- 36 files changed, 102 insertions(+), 87 deletions(-) diff --git a/src/commands/annotations.ts b/src/commands/annotations.ts index 2268467..2677a22 100644 --- a/src/commands/annotations.ts +++ b/src/commands/annotations.ts @@ -46,7 +46,9 @@ export class ToggleFileBlameCommand extends ActiveEditorCommand { super(Commands.ToggleFileBlame); } - execute(editor: TextEditor, uri?: Uri, args: ToggleFileBlameCommandArgs = {}): Thenable { + execute(editor: TextEditor, uri?: Uri, args?: ToggleFileBlameCommandArgs): Thenable { + args = { ...args }; + // Handle the case where we are focused on a non-editor editor (output, debug console) if (editor != null && !isTextEditor(editor)) { if (uri != null && !UriComparer.equals(uri, editor.document.uri)) { @@ -83,7 +85,7 @@ export class ToggleFileHeatmapCommand extends ActiveEditorCommand { super(Commands.ToggleFileHeatmap); } - execute(editor: TextEditor, uri?: Uri, args: ToggleFileBlameCommandArgs = {}): Thenable { + execute(editor: TextEditor, uri?: Uri, args?: ToggleFileBlameCommandArgs): Thenable { const copyArgs: ToggleFileBlameCommandArgs = { ...args, type: FileAnnotationType.Heatmap @@ -98,7 +100,7 @@ export class ToggleFileRecentChangesCommand extends ActiveEditorCommand { super(Commands.ToggleFileRecentChanges); } - execute(editor: TextEditor, uri?: Uri, args: ToggleFileBlameCommandArgs = {}): Thenable { + execute(editor: TextEditor, uri?: Uri, args?: ToggleFileBlameCommandArgs): Thenable { const copyArgs: ToggleFileBlameCommandArgs = { ...args, type: FileAnnotationType.RecentChanges diff --git a/src/commands/closeUnchangedFiles.ts b/src/commands/closeUnchangedFiles.ts index c87fb46..c19d3d1 100644 --- a/src/commands/closeUnchangedFiles.ts +++ b/src/commands/closeUnchangedFiles.ts @@ -20,13 +20,12 @@ export class CloseUnchangedFilesCommand extends ActiveEditorCommand { super(Commands.CloseUnchangedFiles); } - async execute(editor?: TextEditor, uri?: Uri, args: CloseUnchangedFilesCommandArgs = {}) { + async execute(editor?: TextEditor, uri?: Uri, args?: CloseUnchangedFilesCommandArgs) { uri = getCommandUri(uri, editor); + args = { ...args }; try { if (args.uris === undefined) { - args = { ...args }; - const repoPath = await getRepoPathOrPrompt( `Close all files except those changed in which repository${GlyphChars.Ellipsis}` ); diff --git a/src/commands/copyMessageToClipboard.ts b/src/commands/copyMessageToClipboard.ts index 99ecbfe..c7ebbd6 100644 --- a/src/commands/copyMessageToClipboard.ts +++ b/src/commands/copyMessageToClipboard.ts @@ -25,7 +25,7 @@ export class CopyMessageToClipboardCommand extends ActiveEditorCommand { super(Commands.CopyMessageToClipboard); } - protected preExecute(context: CommandContext, args: CopyMessageToClipboardCommandArgs = {}) { + protected preExecute(context: CommandContext, args?: CopyMessageToClipboardCommandArgs) { if (isCommandViewContextWithCommit(context)) { args = { ...args }; args.sha = context.node.commit.sha; @@ -35,12 +35,11 @@ export class CopyMessageToClipboardCommand extends ActiveEditorCommand { return this.execute(context.editor, context.uri, args); } - async execute(editor?: TextEditor, uri?: Uri, args: CopyMessageToClipboardCommandArgs = {}) { + async execute(editor?: TextEditor, uri?: Uri, args?: CopyMessageToClipboardCommandArgs) { uri = getCommandUri(uri, editor); + args = { ...args }; try { - args = { ...args }; - let repoPath; // If we don't have an editor then get the message of the last commit to the branch if (uri == null) { diff --git a/src/commands/copyShaToClipboard.ts b/src/commands/copyShaToClipboard.ts index 32f621b..27f9f48 100644 --- a/src/commands/copyShaToClipboard.ts +++ b/src/commands/copyShaToClipboard.ts @@ -24,7 +24,7 @@ export class CopyShaToClipboardCommand extends ActiveEditorCommand { super(Commands.CopyShaToClipboard); } - protected preExecute(context: CommandContext, args: CopyShaToClipboardCommandArgs = {}) { + protected preExecute(context: CommandContext, args?: CopyShaToClipboardCommandArgs) { if (isCommandViewContextWithCommit(context)) { args = { ...args }; args.sha = context.node.commit.sha; @@ -34,12 +34,11 @@ export class CopyShaToClipboardCommand extends ActiveEditorCommand { return this.execute(context.editor, context.uri, args); } - async execute(editor?: TextEditor, uri?: Uri, args: CopyShaToClipboardCommandArgs = {}) { + async execute(editor?: TextEditor, uri?: Uri, args?: CopyShaToClipboardCommandArgs) { uri = getCommandUri(uri, editor); + args = { ...args }; try { - args = { ...args }; - // If we don't have an editor then get the sha of the last commit to the branch if (uri == null) { const repoPath = await Container.git.getActiveRepoPath(editor); diff --git a/src/commands/diffBranchWith.ts b/src/commands/diffBranchWith.ts index 85f6f50..031c554 100644 --- a/src/commands/diffBranchWith.ts +++ b/src/commands/diffBranchWith.ts @@ -30,15 +30,17 @@ export class DiffBranchWithCommand extends ActiveEditorCommand { ]); } - protected preExecute(context: CommandContext, args: DiffBranchWithCommandArgs = {}) { + protected preExecute(context: CommandContext, args?: DiffBranchWithCommandArgs) { switch (context.command) { case Commands.DiffHeadWith: case Commands.DiffHeadWithBranch: + args = { ...args }; args.ref1 = 'HEAD'; break; case Commands.DiffWorkingWith: case Commands.DiffWorkingWithBranch: + args = { ...args }; args.ref1 = ''; break; } @@ -46,10 +48,11 @@ export class DiffBranchWithCommand extends ActiveEditorCommand { return this.execute(context.editor, context.uri, args); } - async execute(editor?: TextEditor, uri?: Uri, args: DiffBranchWithCommandArgs = {}) { - if (args.ref1 === undefined) return undefined; - + async execute(editor?: TextEditor, uri?: Uri, args?: DiffBranchWithCommandArgs) { uri = getCommandUri(uri, editor); + args = { ...args }; + + if (args.ref1 === undefined) return undefined; try { const repoPath = await getRepoPathOrActiveOrPrompt( diff --git a/src/commands/diffDirectory.ts b/src/commands/diffDirectory.ts index 224d145..2759250 100644 --- a/src/commands/diffDirectory.ts +++ b/src/commands/diffDirectory.ts @@ -32,21 +32,24 @@ export class DiffDirectoryCommand extends ActiveEditorCommand { ]); } - protected async preExecute(context: CommandContext, args: DiffDirectoryCommandArgs = {}) { + protected async preExecute(context: CommandContext, args?: DiffDirectoryCommandArgs) { switch (context.command) { case Commands.DiffDirectoryWithHead: + args = { ...args }; args.ref1 = 'HEAD'; args.ref2 = undefined; break; case Commands.ViewsOpenDirectoryDiff: if (context.type === 'viewItem' && context.node instanceof CompareResultsNode) { + args = { ...args }; [args.ref1, args.ref2] = await context.node.getDiffRefs(); } break; case Commands.ViewsOpenDirectoryDiffWithWorking: if (isCommandViewContextWithRef(context)) { + args = { ...args }; args.ref1 = context.node.ref; args.ref2 = undefined; } @@ -56,8 +59,9 @@ export class DiffDirectoryCommand extends ActiveEditorCommand { return this.execute(context.editor, context.uri, args); } - async execute(editor?: TextEditor, uri?: Uri, args: DiffDirectoryCommandArgs = {}) { + async execute(editor?: TextEditor, uri?: Uri, args?: DiffDirectoryCommandArgs) { uri = getCommandUri(uri, editor); + args = { ...args }; try { const repoPath = await getRepoPathOrActiveOrPrompt( @@ -68,8 +72,6 @@ export class DiffDirectoryCommand extends ActiveEditorCommand { if (!repoPath) return undefined; if (!args.ref1) { - args = { ...args }; - const pick = await new ReferencesQuickPick(repoPath).show( `Compare Working Tree with${GlyphChars.Ellipsis}`, { allowEnteringRefs: true, checkmarks: false } diff --git a/src/commands/diffLineWithPrevious.ts b/src/commands/diffLineWithPrevious.ts index 56d5e10..140f9be 100644 --- a/src/commands/diffLineWithPrevious.ts +++ b/src/commands/diffLineWithPrevious.ts @@ -20,7 +20,7 @@ export class DiffLineWithPreviousCommand extends ActiveEditorCommand { super(Commands.DiffLineWithPrevious); } - async execute(editor?: TextEditor, uri?: Uri, args: DiffLineWithPreviousCommandArgs = {}): Promise { + async execute(editor?: TextEditor, uri?: Uri, args?: DiffLineWithPreviousCommandArgs): Promise { uri = getCommandUri(uri, editor); if (uri == null) return undefined; diff --git a/src/commands/diffLineWithWorking.ts b/src/commands/diffLineWithWorking.ts index 434bf63..ce5a3d9 100644 --- a/src/commands/diffLineWithWorking.ts +++ b/src/commands/diffLineWithWorking.ts @@ -20,7 +20,7 @@ export class DiffLineWithWorkingCommand extends ActiveEditorCommand { super(Commands.DiffLineWithWorking); } - async execute(editor?: TextEditor, uri?: Uri, args: DiffLineWithWorkingCommandArgs = {}): Promise { + async execute(editor?: TextEditor, uri?: Uri, args?: DiffLineWithWorkingCommandArgs): Promise { uri = getCommandUri(uri, editor); if (uri == null) return undefined; diff --git a/src/commands/diffWithNext.ts b/src/commands/diffWithNext.ts index a6ff2a0..a4d5f07 100644 --- a/src/commands/diffWithNext.ts +++ b/src/commands/diffWithNext.ts @@ -22,15 +22,16 @@ export class DiffWithNextCommand extends ActiveEditorCommand { super([Commands.DiffWithNext, Commands.DiffWithNextInDiffLeft]); } - protected preExecute(context: CommandContext, args: DiffWithNextCommandArgs = {}) { + protected preExecute(context: CommandContext, args?: DiffWithNextCommandArgs) { if (context.command === Commands.DiffWithNextInDiffLeft) { + args = { ...args }; args.inDiffLeftEditor = true; } return this.execute(context.editor, context.uri, args); } - async execute(editor?: TextEditor, uri?: Uri, args: DiffWithNextCommandArgs = {}) { + async execute(editor?: TextEditor, uri?: Uri, args?: DiffWithNextCommandArgs) { uri = getCommandUri(uri, editor); if (uri == null) return undefined; diff --git a/src/commands/diffWithPrevious.ts b/src/commands/diffWithPrevious.ts index dd4511f..80d8d0f 100644 --- a/src/commands/diffWithPrevious.ts +++ b/src/commands/diffWithPrevious.ts @@ -21,15 +21,16 @@ export class DiffWithPreviousCommand extends ActiveEditorCommand { super([Commands.DiffWithPrevious, Commands.DiffWithPreviousInDiffRight]); } - protected preExecute(context: CommandContext, args: DiffWithPreviousCommandArgs = {}) { + protected preExecute(context: CommandContext, args?: DiffWithPreviousCommandArgs) { if (context.command === Commands.DiffWithPreviousInDiffRight) { + args = { ...args }; args.inDiffRightEditor = true; } return this.execute(context.editor, context.uri, args); } - async execute(editor?: TextEditor, uri?: Uri, args: DiffWithPreviousCommandArgs = {}) { + async execute(editor?: TextEditor, uri?: Uri, args?: DiffWithPreviousCommandArgs) { uri = getCommandUri(uri, editor); if (uri == null) return undefined; diff --git a/src/commands/diffWithRef.ts b/src/commands/diffWithRef.ts index c006a5d..3b700b4 100644 --- a/src/commands/diffWithRef.ts +++ b/src/commands/diffWithRef.ts @@ -23,7 +23,7 @@ export class DiffWithRefCommand extends ActiveEditorCommand { super([Commands.DiffWithRef, Commands.DiffWithBranch]); } - async execute(editor?: TextEditor, uri?: Uri, args: DiffWithRefCommandArgs = {}) { + async execute(editor?: TextEditor, uri?: Uri, args?: DiffWithRefCommandArgs) { uri = getCommandUri(uri, editor); if (uri == null) return undefined; diff --git a/src/commands/diffWithRevision.ts b/src/commands/diffWithRevision.ts index 1ae5ade..8260489 100644 --- a/src/commands/diffWithRevision.ts +++ b/src/commands/diffWithRevision.ts @@ -25,7 +25,7 @@ export class DiffWithRevisionCommand extends ActiveEditorCommand { super(Commands.DiffWithRevision); } - async execute(editor?: TextEditor, uri?: Uri, args: DiffWithRevisionCommandArgs = {}): Promise { + async execute(editor?: TextEditor, uri?: Uri, args?: DiffWithRevisionCommandArgs): Promise { uri = getCommandUri(uri, editor); if (uri == null) return undefined; diff --git a/src/commands/diffWithWorking.ts b/src/commands/diffWithWorking.ts index 35bbbe7..3692026 100644 --- a/src/commands/diffWithWorking.ts +++ b/src/commands/diffWithWorking.ts @@ -20,7 +20,7 @@ export class DiffWithWorkingCommand extends ActiveEditorCommand { super(Commands.DiffWithWorking); } - async execute(editor?: TextEditor, uri?: Uri, args: DiffWithWorkingCommandArgs = {}): Promise { + async execute(editor?: TextEditor, uri?: Uri, args?: DiffWithWorkingCommandArgs): Promise { uri = getCommandUri(uri, editor); if (uri == null) return undefined; diff --git a/src/commands/exploreRepoAtRevision.ts b/src/commands/exploreRepoAtRevision.ts index 23e95e2..8045bdd 100644 --- a/src/commands/exploreRepoAtRevision.ts +++ b/src/commands/exploreRepoAtRevision.ts @@ -18,7 +18,7 @@ export class ExploreRepoAtRevisionCommand extends ActiveEditorCommand { super(Commands.ExploreRepoAtRevision); } - async execute(editor: TextEditor, uri?: Uri, args: ExploreRepoAtRevisionCommandArgs = {}) { + async execute(editor: TextEditor, uri?: Uri, args?: ExploreRepoAtRevisionCommandArgs) { args = { ...args }; try { diff --git a/src/commands/externalDiff.ts b/src/commands/externalDiff.ts index d3baf66..8afd7ca 100644 --- a/src/commands/externalDiff.ts +++ b/src/commands/externalDiff.ts @@ -65,10 +65,10 @@ export class ExternalDiffCommand extends Command { super([Commands.ExternalDiff, Commands.ExternalDiffAll]); } - protected async preExecute(context: CommandContext, args: ExternalDiffCommandArgs = {}) { - if (isCommandViewContextWithFileCommit(context)) { - args = { ...args }; + protected async preExecute(context: CommandContext, args?: ExternalDiffCommandArgs) { + args = { ...args }; + if (isCommandViewContextWithFileCommit(context)) { const ref1 = GitService.isUncommitted(context.node.commit.previousFileSha) ? '' : context.node.commit.previousFileSha; @@ -87,8 +87,6 @@ export class ExternalDiffCommand extends Command { } if (isCommandViewContextWithFileRefs(context)) { - args = { ...args }; - args.files = [ { uri: GitUri.fromFile(context.node.file, context.node.file.repoPath || context.node.repoPath), @@ -103,13 +101,11 @@ export class ExternalDiffCommand extends Command { if (args.files === undefined) { if (context.type === 'scm-states') { - args = { ...args }; args.files = context.scmResourceStates.map(r => ({ uri: r.resourceUri, staged: (r as Resource).resourceGroupType === ResourceGroupType.Index })); } else if (context.type === 'scm-groups') { - args = { ...args }; args.files = Arrays.filterMap(context.scmResourceGroups[0].resourceStates, r => this.isModified(r) ? { @@ -153,7 +149,9 @@ export class ExternalDiffCommand extends Command { return status === Status.BOTH_MODIFIED || status === Status.INDEX_MODIFIED || status === Status.MODIFIED; } - async execute(args: ExternalDiffCommandArgs = {}) { + async execute(args?: ExternalDiffCommandArgs) { + args = { ...args }; + try { let repoPath; if (args.files === undefined) { diff --git a/src/commands/inviteToLiveShare.ts b/src/commands/inviteToLiveShare.ts index a73a6f0..67fb09e 100644 --- a/src/commands/inviteToLiveShare.ts +++ b/src/commands/inviteToLiveShare.ts @@ -20,7 +20,7 @@ export class InviteToLiveShareCommand extends Command { super(Commands.InviteToLiveShare); } - protected preExecute(context: CommandContext, args: InviteToLiveShareCommandArgs = {}) { + protected preExecute(context: CommandContext, args?: InviteToLiveShareCommandArgs) { if (isCommandViewContextWithContributor(context)) { args = { ...args }; args.email = context.node.contributor.email; @@ -30,8 +30,8 @@ export class InviteToLiveShareCommand extends Command { return this.execute(args); } - async execute(args: InviteToLiveShareCommandArgs = {}) { - if (args.email) { + async execute(args?: InviteToLiveShareCommandArgs) { + if (args != null && args.email) { const contact = await Container.vsls.getContact(args.email); if (contact != null) { return contact.invite(); diff --git a/src/commands/openBranchInRemote.ts b/src/commands/openBranchInRemote.ts index 4d5414d..f5797f7 100644 --- a/src/commands/openBranchInRemote.ts +++ b/src/commands/openBranchInRemote.ts @@ -27,7 +27,7 @@ export class OpenBranchInRemoteCommand extends ActiveEditorCommand { super(Commands.OpenBranchInRemote); } - protected preExecute(context: CommandContext, args: OpenBranchInRemoteCommandArgs = {}) { + protected preExecute(context: CommandContext, args?: OpenBranchInRemoteCommandArgs) { if (isCommandViewContextWithBranch(context)) { args = { ...args }; args.branch = context.node.branch.name; @@ -37,7 +37,7 @@ export class OpenBranchInRemoteCommand extends ActiveEditorCommand { return this.execute(context.editor, context.uri, args); } - async execute(editor?: TextEditor, uri?: Uri, args: OpenBranchInRemoteCommandArgs = {}) { + async execute(editor?: TextEditor, uri?: Uri, args?: OpenBranchInRemoteCommandArgs) { uri = getCommandUri(uri, editor); const gitUri = uri && (await GitUri.fromUri(uri)); @@ -49,10 +49,10 @@ export class OpenBranchInRemoteCommand extends ActiveEditorCommand { ); if (!repoPath) return undefined; + args = { ...args }; + try { if (args.branch === undefined) { - args = { ...args }; - const pick = await new ReferencesQuickPick(repoPath).show( `Open which branch on remote${GlyphChars.Ellipsis}`, { diff --git a/src/commands/openBranchesInRemote.ts b/src/commands/openBranchesInRemote.ts index a73546d..eaa2ba6 100644 --- a/src/commands/openBranchesInRemote.ts +++ b/src/commands/openBranchesInRemote.ts @@ -25,7 +25,7 @@ export class OpenBranchesInRemoteCommand extends ActiveEditorCommand { super(Commands.OpenBranchesInRemote); } - protected preExecute(context: CommandContext, args: OpenBranchesInRemoteCommandArgs = {}) { + protected preExecute(context: CommandContext, args?: OpenBranchesInRemoteCommandArgs) { if (isCommandViewContextWithRemote(context)) { args = { ...args }; args.remote = context.node.remote.name; @@ -34,7 +34,7 @@ export class OpenBranchesInRemoteCommand extends ActiveEditorCommand { return this.execute(context.editor, context.uri, args); } - async execute(editor?: TextEditor, uri?: Uri, args: OpenBranchesInRemoteCommandArgs = {}) { + async execute(editor?: TextEditor, uri?: Uri, args?: OpenBranchesInRemoteCommandArgs) { uri = getCommandUri(uri, editor); const gitUri = uri && (await GitUri.fromUri(uri)); @@ -53,7 +53,7 @@ export class OpenBranchesInRemoteCommand extends ActiveEditorCommand { resource: { type: RemoteResourceType.Branches }, - remote: args.remote, + remote: args && args.remote, remotes: remotes }; return commands.executeCommand(Commands.OpenInRemote, uri, commandArgs); diff --git a/src/commands/openChangedFiles.ts b/src/commands/openChangedFiles.ts index a4bfad9..2060f0c 100644 --- a/src/commands/openChangedFiles.ts +++ b/src/commands/openChangedFiles.ts @@ -17,13 +17,12 @@ export class OpenChangedFilesCommand extends ActiveEditorCommand { super(Commands.OpenChangedFiles); } - async execute(editor?: TextEditor, uri?: Uri, args: OpenChangedFilesCommandArgs = {}) { + async execute(editor?: TextEditor, uri?: Uri, args?: OpenChangedFilesCommandArgs) { uri = getCommandUri(uri, editor); + args = { ...args }; try { if (args.uris === undefined) { - args = { ...args }; - const repoPath = await getRepoPathOrPrompt( `Open all files changed in which repository${GlyphChars.Ellipsis}` ); diff --git a/src/commands/openCommitInRemote.ts b/src/commands/openCommitInRemote.ts index 09046ea..030c8e3 100644 --- a/src/commands/openCommitInRemote.ts +++ b/src/commands/openCommitInRemote.ts @@ -31,7 +31,7 @@ export class OpenCommitInRemoteCommand extends ActiveEditorCommand { super(Commands.OpenCommitInRemote); } - protected preExecute(context: CommandContext, args: OpenCommitInRemoteCommandArgs = {}) { + protected preExecute(context: CommandContext, args?: OpenCommitInRemoteCommandArgs) { if (isCommandViewContextWithCommit(context)) { args = { ...args }; args.sha = context.node.commit.sha; @@ -41,12 +41,15 @@ export class OpenCommitInRemoteCommand extends ActiveEditorCommand { return this.execute(context.editor, context.uri, args); } - async execute(editor?: TextEditor, uri?: Uri, args: OpenCommitInRemoteCommandArgs = {}) { + async execute(editor?: TextEditor, uri?: Uri, args?: OpenCommitInRemoteCommandArgs) { uri = getCommandUri(uri, editor); if (uri == null) return undefined; + const gitUri = await GitUri.fromUri(uri); if (!gitUri.repoPath) return undefined; + args = { ...args }; + try { if (args.sha === undefined) { const blameline = editor == null ? 0 : editor.selection.active.line; diff --git a/src/commands/openFileRevision.ts b/src/commands/openFileRevision.ts index 31e4e45..e233611 100644 --- a/src/commands/openFileRevision.ts +++ b/src/commands/openFileRevision.ts @@ -50,7 +50,7 @@ export class OpenFileRevisionCommand extends ActiveEditorCommand { super(Commands.OpenFileRevision); } - async execute(editor: TextEditor | undefined, uri?: Uri, args: OpenFileRevisionCommandArgs = {}) { + async execute(editor: TextEditor | undefined, uri?: Uri, args?: OpenFileRevisionCommandArgs) { args = { ...args }; if (args.line === undefined) { args.line = editor == null ? 0 : editor.selection.active.line; diff --git a/src/commands/openFileRevisionFrom.ts b/src/commands/openFileRevisionFrom.ts index 7130bae..2994e92 100644 --- a/src/commands/openFileRevisionFrom.ts +++ b/src/commands/openFileRevisionFrom.ts @@ -19,13 +19,15 @@ export class OpenFileRevisionFromCommand extends ActiveEditorCommand { super([Commands.OpenFileRevisionFrom, Commands.OpenFileRevisionFromBranch]); } - async execute(editor: TextEditor | undefined, uri?: Uri, args: OpenFileRevisionFromCommandArgs = {}) { + async execute(editor: TextEditor | undefined, uri?: Uri, args?: OpenFileRevisionFromCommandArgs) { uri = getCommandUri(uri, editor); if (uri == null) return undefined; const gitUri = await GitUri.fromUri(uri); if (!gitUri.repoPath) return undefined; + args = { ...args }; + if (args.reference === undefined) { const placeHolder = `Open revision of ${gitUri.getFormattedPath()}${ gitUri.sha ? ` ${Strings.pad(GlyphChars.Dot, 1, 1)} ${gitUri.shortSha}` : '' diff --git a/src/commands/openInRemote.ts b/src/commands/openInRemote.ts index 4f87dfb..a9647c7 100644 --- a/src/commands/openInRemote.ts +++ b/src/commands/openInRemote.ts @@ -23,12 +23,12 @@ export class OpenInRemoteCommand extends ActiveEditorCommand { super(Commands.OpenInRemote); } - async execute(editor: TextEditor, uri?: Uri, args: OpenInRemoteCommandArgs = {}) { + async execute(editor: TextEditor, uri?: Uri, args?: OpenInRemoteCommandArgs) { args = { ...args }; if (args.remotes === undefined || args.resource === undefined) return undefined; if (args.remote !== undefined) { - const remotes = args.remotes.filter(r => r.name === args.remote); + const remotes = args.remotes.filter(r => r.name === args!.remote); // Only filter if we get some results if (remotes.length > 0) { args.remotes = remotes; diff --git a/src/commands/openRepoInRemote.ts b/src/commands/openRepoInRemote.ts index 2920598..9c11d18 100644 --- a/src/commands/openRepoInRemote.ts +++ b/src/commands/openRepoInRemote.ts @@ -25,7 +25,7 @@ export class OpenRepoInRemoteCommand extends ActiveEditorCommand { super(Commands.OpenRepoInRemote); } - protected preExecute(context: CommandContext, args: OpenRepoInRemoteCommandArgs = {}) { + protected preExecute(context: CommandContext, args?: OpenRepoInRemoteCommandArgs) { if (isCommandViewContextWithRemote(context)) { args = { ...args }; args.remote = context.node.remote.name; @@ -34,7 +34,7 @@ export class OpenRepoInRemoteCommand extends ActiveEditorCommand { return this.execute(context.editor, context.uri, args); } - async execute(editor?: TextEditor, uri?: Uri, args: OpenRepoInRemoteCommandArgs = {}) { + async execute(editor?: TextEditor, uri?: Uri, args?: OpenRepoInRemoteCommandArgs) { uri = getCommandUri(uri, editor); const gitUri = uri && (await GitUri.fromUri(uri)); @@ -53,7 +53,7 @@ export class OpenRepoInRemoteCommand extends ActiveEditorCommand { resource: { type: RemoteResourceType.Repo }, - remote: args.remote, + remote: args && args.remote, remotes: remotes }; return commands.executeCommand(Commands.OpenInRemote, uri, commandArgs); diff --git a/src/commands/openRevisionFile.ts b/src/commands/openRevisionFile.ts index 9d95f80..9029a9f 100644 --- a/src/commands/openRevisionFile.ts +++ b/src/commands/openRevisionFile.ts @@ -20,7 +20,7 @@ export class OpenRevisionFileCommand extends ActiveEditorCommand { super(Commands.OpenRevisionFile); } - async execute(editor: TextEditor, uri?: Uri, args: OpenRevisionFileCommandArgs = {}) { + async execute(editor: TextEditor, uri?: Uri, args?: OpenRevisionFileCommandArgs) { args = { ...args }; if (args.line === undefined) { args.line = editor == null ? 0 : editor.selection.active.line; diff --git a/src/commands/openWorkingFile.ts b/src/commands/openWorkingFile.ts index 23b96fb..6dac9c2 100644 --- a/src/commands/openWorkingFile.ts +++ b/src/commands/openWorkingFile.ts @@ -20,7 +20,7 @@ export class OpenWorkingFileCommand extends ActiveEditorCommand { super(Commands.OpenWorkingFile); } - async execute(editor: TextEditor, uri?: Uri, args: OpenWorkingFileCommandArgs = {}) { + async execute(editor: TextEditor, uri?: Uri, args?: OpenWorkingFileCommandArgs) { args = { ...args }; if (args.line === undefined) { args.line = editor == null ? 0 : editor.selection.active.line; diff --git a/src/commands/searchCommits.ts b/src/commands/searchCommits.ts index 2db2a65..904d316 100644 --- a/src/commands/searchCommits.ts +++ b/src/commands/searchCommits.ts @@ -25,7 +25,7 @@ export class SearchCommitsCommand extends Command { super([Commands.SearchCommits, Commands.SearchCommitsInView]); } - protected preExecute(context: CommandContext, args: SearchCommitsCommandArgs = {}) { + protected preExecute(context: CommandContext, args?: SearchCommitsCommandArgs) { if (context.type === 'viewItem') { args = { ...args }; args.showInView = true; @@ -47,7 +47,9 @@ export class SearchCommitsCommand extends Command { return this.execute(args); } - async execute(args: SearchCommitsCommandArgs = {}) { + async execute(args?: SearchCommitsCommandArgs) { + args = { ...args }; + let repo; if (args.repoPath !== undefined) { repo = await Container.git.getRepository(args.repoPath); diff --git a/src/commands/showQuickBranchHistory.ts b/src/commands/showQuickBranchHistory.ts index eeb10a6..e94f86a 100644 --- a/src/commands/showQuickBranchHistory.ts +++ b/src/commands/showQuickBranchHistory.ts @@ -30,7 +30,7 @@ export class ShowQuickBranchHistoryCommand extends ActiveEditorCachedCommand { super(Commands.ShowQuickBranchHistory); } - async execute(editor?: TextEditor, uri?: Uri, args: ShowQuickBranchHistoryCommandArgs = {}) { + async execute(editor?: TextEditor, uri?: Uri, args?: ShowQuickBranchHistoryCommandArgs) { uri = getCommandUri(uri, editor); const gitUri = uri && (await GitUri.fromUri(uri)); diff --git a/src/commands/showQuickCommitDetails.ts b/src/commands/showQuickCommitDetails.ts index b83c71d..3ec1395 100644 --- a/src/commands/showQuickCommitDetails.ts +++ b/src/commands/showQuickCommitDetails.ts @@ -41,7 +41,7 @@ export class ShowQuickCommitDetailsCommand extends ActiveEditorCachedCommand { super([Commands.ShowCommitInView, Commands.ShowQuickCommitDetails]); } - protected preExecute(context: CommandContext, args: ShowQuickCommitDetailsCommandArgs = {}) { + protected preExecute(context: CommandContext, args?: ShowQuickCommitDetailsCommandArgs) { if (context.command === Commands.ShowCommitInView) { args = { ...args }; args.showInView = true; @@ -59,7 +59,7 @@ export class ShowQuickCommitDetailsCommand extends ActiveEditorCachedCommand { return this.execute(context.editor, context.uri, args); } - async execute(editor?: TextEditor, uri?: Uri, args: ShowQuickCommitDetailsCommandArgs = {}) { + async execute(editor?: TextEditor, uri?: Uri, args?: ShowQuickCommitDetailsCommandArgs) { uri = getCommandUri(uri, editor); if (uri == null) return undefined; diff --git a/src/commands/showQuickCommitFileDetails.ts b/src/commands/showQuickCommitFileDetails.ts index c87a6ad..bde53ec 100644 --- a/src/commands/showQuickCommitFileDetails.ts +++ b/src/commands/showQuickCommitFileDetails.ts @@ -38,7 +38,7 @@ export class ShowQuickCommitFileDetailsCommand extends ActiveEditorCachedCommand super([Commands.ShowQuickCommitFileDetails, Commands.ShowQuickRevisionDetails]); } - protected async preExecute(context: CommandContext, args: ShowQuickCommitFileDetailsCommandArgs = {}) { + protected async preExecute(context: CommandContext, args?: ShowQuickCommitFileDetailsCommandArgs) { if (context.command === Commands.ShowQuickRevisionDetails && context.editor !== undefined) { args = { ...args }; @@ -58,10 +58,12 @@ export class ShowQuickCommitFileDetailsCommand extends ActiveEditorCachedCommand return this.execute(context.editor, context.uri, args); } - async execute(editor?: TextEditor, uri?: Uri, args: ShowQuickCommitFileDetailsCommandArgs = {}) { + async execute(editor?: TextEditor, uri?: Uri, args?: ShowQuickCommitFileDetailsCommandArgs) { uri = getCommandUri(uri, editor); if (uri == null) return undefined; + args = { ...args }; + let gitUri; if (args.revisionUri !== undefined) { gitUri = GitUri.fromRevisionUri(Uri.parse(args.revisionUri)); @@ -70,7 +72,6 @@ export class ShowQuickCommitFileDetailsCommand extends ActiveEditorCachedCommand gitUri = await GitUri.fromUri(uri); } - args = { ...args }; if (args.sha === undefined) { if (editor == null) return undefined; diff --git a/src/commands/showQuickCurrentBranchHistory.ts b/src/commands/showQuickCurrentBranchHistory.ts index 7b38498..a568a92 100644 --- a/src/commands/showQuickCurrentBranchHistory.ts +++ b/src/commands/showQuickCurrentBranchHistory.ts @@ -18,7 +18,7 @@ export class ShowQuickCurrentBranchHistoryCommand extends ActiveEditorCachedComm super(Commands.ShowQuickCurrentBranchHistory); } - async execute(editor?: TextEditor, uri?: Uri, args: ShowQuickCurrentBranchHistoryCommandArgs = {}) { + async execute(editor?: TextEditor, uri?: Uri, args?: ShowQuickCurrentBranchHistoryCommandArgs) { uri = getCommandUri(uri, editor); try { @@ -35,7 +35,7 @@ export class ShowQuickCurrentBranchHistoryCommand extends ActiveEditorCachedComm const commandArgs: ShowQuickBranchHistoryCommandArgs = { branch: branch.name, repoPath: repoPath, - goBackCommand: args.goBackCommand + goBackCommand: args && args.goBackCommand }; return commands.executeCommand(Commands.ShowQuickBranchHistory, uri, commandArgs); } catch (ex) { diff --git a/src/commands/showQuickFileHistory.ts b/src/commands/showQuickFileHistory.ts index 6999457..2f5e323 100644 --- a/src/commands/showQuickFileHistory.ts +++ b/src/commands/showQuickFileHistory.ts @@ -32,7 +32,7 @@ export class ShowQuickFileHistoryCommand extends ActiveEditorCachedCommand { super([Commands.ShowFileHistoryInView, Commands.ShowQuickFileHistory]); } - protected preExecute(context: CommandContext, args: ShowQuickFileHistoryCommandArgs = {}) { + protected preExecute(context: CommandContext, args?: ShowQuickFileHistoryCommandArgs) { if (context.command === Commands.ShowFileHistoryInView) { args = { ...args }; args.showInView = true; @@ -41,20 +41,20 @@ export class ShowQuickFileHistoryCommand extends ActiveEditorCachedCommand { return this.execute(context.editor, context.uri, args); } - async execute(editor?: TextEditor, uri?: Uri, args: ShowQuickFileHistoryCommandArgs = {}) { + async execute(editor?: TextEditor, uri?: Uri, args?: ShowQuickFileHistoryCommandArgs) { uri = getCommandUri(uri, editor); if (uri == null) return commands.executeCommand(Commands.ShowQuickCurrentBranchHistory); const gitUri = await GitUri.fromUri(uri); + args = { ...args }; + if (args.showInView) { await Container.fileHistoryView.showHistoryForUri(gitUri); return undefined; } - args = { ...args }; - const placeHolder = `${gitUri.getFormattedPath({ suffix: args.reference ? ` (${args.reference.name})` : undefined })}${gitUri.sha ? ` ${Strings.pad(GlyphChars.Dot, 1, 1)} ${gitUri.shortSha}` : ''}`; diff --git a/src/commands/showQuickRepoStatus.ts b/src/commands/showQuickRepoStatus.ts index 50c7533..f28e866 100644 --- a/src/commands/showQuickRepoStatus.ts +++ b/src/commands/showQuickRepoStatus.ts @@ -17,7 +17,7 @@ export class ShowQuickRepoStatusCommand extends ActiveEditorCachedCommand { super(Commands.ShowQuickRepoStatus); } - async execute(editor?: TextEditor, uri?: Uri, args: ShowQuickRepoStatusCommandArgs = {}) { + async execute(editor?: TextEditor, uri?: Uri, args?: ShowQuickRepoStatusCommandArgs) { uri = getCommandUri(uri, editor); try { @@ -31,7 +31,7 @@ export class ShowQuickRepoStatusCommand extends ActiveEditorCachedCommand { const status = await Container.git.getStatusForRepo(repoPath); if (status === undefined) return window.showWarningMessage('Unable to show repository status'); - const pick = await RepoStatusQuickPick.show(status, args.goBackCommand); + const pick = await RepoStatusQuickPick.show(status, args && args.goBackCommand); if (pick === undefined) return undefined; if (pick instanceof CommandQuickPickItem) return pick.execute(); diff --git a/src/commands/showQuickStashList.ts b/src/commands/showQuickStashList.ts index da24bf1..2427ee4 100644 --- a/src/commands/showQuickStashList.ts +++ b/src/commands/showQuickStashList.ts @@ -18,7 +18,7 @@ export class ShowQuickStashListCommand extends ActiveEditorCachedCommand { super(Commands.ShowQuickStashList); } - async execute(editor?: TextEditor, uri?: Uri, args: ShowQuickStashListCommandArgs = {}) { + async execute(editor?: TextEditor, uri?: Uri, args?: ShowQuickStashListCommandArgs) { uri = getCommandUri(uri, editor); const repoPath = await getRepoPathOrActiveOrPrompt( @@ -38,7 +38,7 @@ export class ShowQuickStashListCommand extends ActiveEditorCachedCommand { // Create a command to get back to here const currentCommandArgs: ShowQuickStashListCommandArgs = { - goBackCommand: args.goBackCommand + goBackCommand: args && args.goBackCommand }; const currentCommand = new CommandQuickPickItem( { @@ -53,7 +53,7 @@ export class ShowQuickStashListCommand extends ActiveEditorCachedCommand { stash, 'list', progressCancellation, - args.goBackCommand, + args && args.goBackCommand, currentCommand ); if (pick === undefined) return undefined; diff --git a/src/commands/stashDelete.ts b/src/commands/stashDelete.ts index 57b5306..0231480 100644 --- a/src/commands/stashDelete.ts +++ b/src/commands/stashDelete.ts @@ -19,7 +19,7 @@ export class StashDeleteCommand extends Command { super(Commands.StashDelete); } - protected preExecute(context: CommandContext, args: StashDeleteCommandArgs = {}) { + protected preExecute(context: CommandContext, args?: StashDeleteCommandArgs) { if (isCommandViewContextWithCommit(context)) { args = { ...args }; args.stashItem = context.node.commit; @@ -28,7 +28,9 @@ export class StashDeleteCommand extends Command { return this.execute(args); } - async execute(args: StashDeleteCommandArgs = {}) { + async execute(args?: StashDeleteCommandArgs) { + args = { ...args }; + let repo; if (args.stashItem !== undefined || args.repoPath !== undefined) { repo = await Container.git.getRepository((args.stashItem && args.stashItem.repoPath) || args.repoPath!); diff --git a/src/commands/stashSave.ts b/src/commands/stashSave.ts index 5a54094..af38fac 100644 --- a/src/commands/stashSave.ts +++ b/src/commands/stashSave.ts @@ -29,7 +29,7 @@ export class StashSaveCommand extends Command { super([Commands.StashSave, Commands.StashSaveFiles]); } - protected preExecute(context: CommandContext, args: StashSaveCommandArgs = {}) { + protected preExecute(context: CommandContext, args?: StashSaveCommandArgs) { if (isCommandViewContextWithFile(context)) { args = { ...args }; args.repoPath = context.node.file.repoPath || context.node.repoPath; @@ -59,7 +59,9 @@ export class StashSaveCommand extends Command { return this.execute(args); } - async execute(args: StashSaveCommandArgs = {}) { + async execute(args?: StashSaveCommandArgs) { + args = { ...args }; + let repo; if (args.uris !== undefined || args.repoPath !== undefined) { repo = await Container.git.getRepository((args.uris && args.uris[0]) || args.repoPath!);