Browse Source

Fixes #872 - protects against null args

main
Eric Amodio 5 years ago
parent
commit
bd92919b36
3 changed files with 15 additions and 12 deletions
  1. +4
    -2
      src/commands/copyRemoteFileUrlToClipboard.ts
  2. +5
    -4
      src/commands/openFileInRemote.ts
  3. +6
    -6
      src/commands/stashApply.ts

+ 4
- 2
src/commands/copyRemoteFileUrlToClipboard.ts View File

@ -24,7 +24,7 @@ export class CopyRemoteFileUrlToClipboardCommand extends ActiveEditorCommand {
super(Commands.CopyRemoteFileUrlToClipboard);
}
protected preExecute(context: CommandContext, args: CopyRemoteFileUrlToClipboardCommandArgs = { range: true }) {
protected preExecute(context: CommandContext, args?: CopyRemoteFileUrlToClipboardCommandArgs) {
if (context.type === 'uris' || context.type === 'scm-states') {
args = { ...args, range: false };
} else if (isCommandViewContextWithCommit(context)) {
@ -45,7 +45,9 @@ export class CopyRemoteFileUrlToClipboardCommand extends ActiveEditorCommand {
return this.execute(context.editor, context.uri, args);
}
async execute(editor?: TextEditor, uri?: Uri, args: CopyRemoteFileUrlToClipboardCommandArgs = { range: true }) {
async execute(editor?: TextEditor, uri?: Uri, args?: CopyRemoteFileUrlToClipboardCommandArgs) {
args = { range: true, ...args };
if (args.sha === undefined) {
uri = getCommandUri(uri, editor);
if (uri == null) return undefined;

+ 5
- 4
src/commands/openFileInRemote.ts View File

@ -31,10 +31,9 @@ export class OpenFileInRemoteCommand extends ActiveEditorCommand {
super(Commands.OpenFileInRemote);
}
protected preExecute(context: CommandContext, args: OpenFileInRemoteCommandArgs = { range: true }) {
protected preExecute(context: CommandContext, args?: OpenFileInRemoteCommandArgs) {
if (isCommandViewContextWithCommit(context)) {
args = { ...args };
args.range = false;
args = { ...args, range: false };
if (isCommandViewContextWithBranch(context)) {
args.branch = context.node.branch !== undefined ? context.node.branch.name : undefined;
}
@ -49,13 +48,15 @@ export class OpenFileInRemoteCommand extends ActiveEditorCommand {
return this.execute(context.editor, context.uri, args);
}
async execute(editor?: TextEditor, uri?: Uri, args: OpenFileInRemoteCommandArgs = { range: true }) {
async execute(editor?: TextEditor, uri?: Uri, args?: OpenFileInRemoteCommandArgs) {
uri = getCommandUri(uri, editor);
if (uri == null) return undefined;
const gitUri = await GitUri.fromUri(uri);
if (!gitUri.repoPath) return undefined;
args = { range: true, ...args };
try {
const remotes = await Container.git.getRemotes(gitUri.repoPath);
const range =

+ 6
- 6
src/commands/stashApply.ts View File

@ -27,19 +27,19 @@ export class StashApplyCommand extends Command {
super(Commands.StashApply);
}
protected preExecute(context: CommandContext, args: StashApplyCommandArgs = { deleteAfter: false }) {
protected preExecute(context: CommandContext, args?: StashApplyCommandArgs) {
if (isCommandViewContextWithCommit<GitStashCommit>(context)) {
args = { ...args };
args.stashItem = context.node.commit;
args = { ...args, stashItem: context.node.commit };
} else if (isCommandViewContextWithRepo(context)) {
args = { ...args };
args.repoPath = context.node.repo.path;
args = { ...args, repoPath: context.node.repo.path };
}
return this.execute(args);
}
async execute(args: StashApplyCommandArgs = { deleteAfter: false }) {
async execute(args?: StashApplyCommandArgs) {
args = { deleteAfter: false, ...args };
let repo;
if (args.stashItem !== undefined || args.repoPath !== undefined) {
repo = await Container.git.getRepository((args.stashItem && args.stashItem.repoPath) || args.repoPath!);

Loading…
Cancel
Save