Ver a proveniência

Fixes repo fallback on many commandsFixes #366 - deals null parameters from command callbacks

main
Eric Amodio há 6 anos
ascendente
cometimento
6d15b90fa1
37 ficheiros alterados com 151 adições e 116 eliminações
  1. +5
    -0
      CHANGELOG.md
  2. +2
    -2
      src/commands/clearFileAnnotations.ts
  3. +7
    -8
      src/commands/closeUnchangedFiles.ts
  4. +23
    -1
      src/commands/common.ts
  5. +1
    -1
      src/commands/copyMessageToClipboard.ts
  6. +1
    -1
      src/commands/copyShaToClipboard.ts
  7. +3
    -4
      src/commands/diffBranchWithBranch.ts
  8. +3
    -4
      src/commands/diffDirectory.ts
  9. +2
    -2
      src/commands/diffLineWithPrevious.ts
  10. +2
    -2
      src/commands/diffLineWithWorking.ts
  11. +2
    -2
      src/commands/diffWithBranch.ts
  12. +2
    -2
      src/commands/diffWithNext.ts
  13. +2
    -2
      src/commands/diffWithPrevious.ts
  14. +2
    -2
      src/commands/diffWithRevision.ts
  15. +2
    -2
      src/commands/diffWithWorking.ts
  16. +7
    -8
      src/commands/externalDiff.ts
  17. +3
    -3
      src/commands/openBranchInRemote.ts
  18. +3
    -2
      src/commands/openBranchesInRemote.ts
  19. +4
    -4
      src/commands/openChangedFiles.ts
  20. +2
    -2
      src/commands/openCommitInRemote.ts
  21. +2
    -2
      src/commands/openFileInRemote.ts
  22. +3
    -3
      src/commands/openFileRevision.ts
  23. +3
    -2
      src/commands/openRepoInRemote.ts
  24. +3
    -3
      src/commands/openWorkingFile.ts
  25. +6
    -12
      src/commands/showCommitSearch.ts
  26. +13
    -5
      src/commands/showQuickBranchHistory.ts
  27. +2
    -2
      src/commands/showQuickCommitDetails.ts
  28. +2
    -2
      src/commands/showQuickCommitFileDetails.ts
  29. +5
    -4
      src/commands/showQuickCurrentBranchHistory.ts
  30. +1
    -1
      src/commands/showQuickFileHistory.ts
  31. +4
    -4
      src/commands/showQuickRepoStatus.ts
  32. +3
    -4
      src/commands/showQuickStashList.ts
  33. +3
    -3
      src/commands/toggleFileBlame.ts
  34. +2
    -2
      src/constants.ts
  35. +1
    -1
      src/git/gitUri.ts
  36. +19
    -11
      src/gitService.ts
  37. +1
    -1
      src/views/gitExplorer.ts

+ 5
- 0
CHANGELOG.md Ver ficheiro

@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/).
## Unreleased
### Fixed
- Fixes many issues where commands wouldn't work if the active file wasn't part of an open repository — now GitLens will try to find the best repository otherwise it will open a repository quick pick menu if there is more than one
- Fixes [#366](https://github.com/eamodio/vscode-gitlens/issues/366) - Running a GitLens command from a keybinding fails (more cases)
## [8.3.1] - 2018-05-18
### Added
- Adds the ability to control where the *GitLens*, *GitLens History*, and *GitLens Results* explorers are shown 🎉 — closes [#213](https://github.com/eamodio/vscode-gitlens/issues/213), [#377](https://github.com/eamodio/vscode-gitlens/issues/377)

+ 2
- 2
src/commands/clearFileAnnotations.ts Ver ficheiro

@ -12,10 +12,10 @@ export class ClearFileAnnotationsCommand extends EditorCommand {
}
async execute(editor: TextEditor, edit: TextEditorEdit, uri?: Uri): Promise<any> {
if (editor === undefined) return undefined;
if (editor == null) return undefined;
// Handle the case where we are focused on a non-editor editor (output, debug console)
if (uri !== undefined && !UriComparer.equals(uri, editor.document.uri)) {
if (uri != null && !UriComparer.equals(uri, editor.document.uri)) {
const e = window.visibleTextEditors.find(e => UriComparer.equals(uri, e.document.uri));
if (e !== undefined) {
editor = e;

+ 7
- 8
src/commands/closeUnchangedFiles.ts Ver ficheiro

@ -1,12 +1,11 @@
'use strict';
import { commands, TextEditor, Uri, window } from 'vscode';
import { ActiveEditorTracker } from '../trackers/activeEditorTracker';
import { ActiveEditorCommand, Commands, getCommandUri } from './common';
import { ActiveEditorCommand, Commands, getCommandUri, getRepoPathOrActiveOrPrompt } from './common';
import { TextEditorComparer, UriComparer } from '../comparers';
import { BuiltInCommands } from '../constants';
import { BuiltInCommands, GlyphChars } from '../constants';
import { Container } from '../container';
import { Logger } from '../logger';
import { Messages } from '../messages';
export interface CloseUnchangedFilesCommandArgs {
uris?: Uri[];
@ -25,8 +24,8 @@ export class CloseUnchangedFilesCommand extends ActiveEditorCommand {
if (args.uris === undefined) {
args = { ...args };
const repoPath = await Container.git.getRepoPath(uri);
if (!repoPath) return Messages.showNoRepositoryWarningMessage(`Unable to close unchanged files`);
const repoPath = await getRepoPathOrActiveOrPrompt(uri, editor, `Close unchanged files in which repository${GlyphChars.Ellipsis}`);
if (!repoPath) return undefined;
const status = await Container.git.getStatusForRepo(repoPath);
if (status === undefined) return window.showWarningMessage(`Unable to close unchanged files`);
@ -40,9 +39,9 @@ export class CloseUnchangedFilesCommand extends ActiveEditorCommand {
let count = 0;
let previous = undefined;
let editor = window.activeTextEditor;
editor = window.activeTextEditor;
while (true) {
if (editor !== undefined) {
if (editor != null) {
if (TextEditorComparer.equals(previous, editor, { useId: true, usePosition: true })) {
break;
}
@ -63,7 +62,7 @@ export class CloseUnchangedFilesCommand extends ActiveEditorCommand {
previous = editor;
editor = await editorTracker.awaitClose(500);
if (previous === undefined && editor === undefined) {
if (previous === undefined && editor == null) {
count++;
// This is such a shitty hack, but I can't figure out any other reliable way to know that we've cycled through all the editors :(
if (count >= 4) {

+ 23
- 1
src/commands/common.ts Ver ficheiro

@ -7,6 +7,7 @@ import { GitBranch, GitCommit, GitRemote, GitUri } from '../gitService';
import { Logger } from '../logger';
// import { Telemetry } from '../telemetry';
import * as path from 'path';
import { CommandQuickPickItem, RepositoriesQuickPick } from '../quickPicks/quickPicks';
export enum Commands {
ClearFileAnnotations = 'gitlens.clearFileAnnotations',
@ -77,6 +78,27 @@ export function getCommandUri(uri?: Uri, editor?: TextEditor): Uri | undefined {
return document.uri;
}
export async function getRepoPathOrActiveOrPrompt(uri: Uri | undefined, editor: TextEditor | undefined, placeholder: string, goBackCommand?: CommandQuickPickItem) {
let repoPath = await Container.git.getRepoPathOrActive(uri, editor);
if (!repoPath) {
const pick = await RepositoriesQuickPick.show(placeholder, goBackCommand);
if (pick instanceof CommandQuickPickItem) {
await pick.execute();
return undefined;
}
if (pick === undefined) {
if (goBackCommand !== undefined) {
await goBackCommand.execute();
}
return undefined;
}
repoPath = pick.repoPath;
}
return repoPath;
}
export interface CommandContextParsingOptions {
editor: boolean;
uri: boolean;
@ -138,7 +160,7 @@ function isScmResourceGroup(group: any): group is SourceControlResourceGroup {
function isScmResourceState(state: any): state is SourceControlResourceState {
if (state == null) return false;
return (state as SourceControlResourceState).resourceUri !== undefined;
return (state as SourceControlResourceState).resourceUri != null;
}
function isTextEditor(editor: any): editor is TextEditor {

+ 1
- 1
src/commands/copyMessageToClipboard.ts Ver ficheiro

@ -36,7 +36,7 @@ export class CopyMessageToClipboardCommand extends ActiveEditorCommand {
args = { ...args };
// If we don't have an editor then get the message of the last commit to the branch
if (uri === undefined) {
if (uri == null) {
const repoPath = await Container.git.getActiveRepoPath(editor);
if (!repoPath) return undefined;

+ 1
- 1
src/commands/copyShaToClipboard.ts Ver ficheiro

@ -34,7 +34,7 @@ export class CopyShaToClipboardCommand extends ActiveEditorCommand {
args = { ...args };
// If we don't have an editor then get the sha of the last commit to the branch
if (uri === undefined) {
if (uri == null) {
const repoPath = await Container.git.getActiveRepoPath(editor);
if (!repoPath) return undefined;

+ 3
- 4
src/commands/diffBranchWithBranch.ts Ver ficheiro

@ -1,10 +1,9 @@
'use strict';
import { CancellationTokenSource, TextEditor, Uri, window } from 'vscode';
import { ActiveEditorCommand, CommandContext, Commands, getCommandUri } from './common';
import { ActiveEditorCommand, CommandContext, Commands, getCommandUri, getRepoPathOrActiveOrPrompt } from './common';
import { GlyphChars } from '../constants';
import { Container } from '../container';
import { Logger } from '../logger';
import { Messages } from '../messages';
import { BranchesAndTagsQuickPick, CommandQuickPickItem } from '../quickPicks/quickPicks';
export interface DiffBranchWithBranchCommandArgs {
@ -40,8 +39,8 @@ export class DiffBranchWithBranchCommand extends ActiveEditorCommand {
let progressCancellation: CancellationTokenSource | undefined;
try {
const repoPath = await Container.git.getRepoPath(uri);
if (!repoPath) return Messages.showNoRepositoryWarningMessage(`Unable to open branch compare`);
const repoPath = await getRepoPathOrActiveOrPrompt(uri, editor, `Compare with branch or tag in which repository${GlyphChars.Ellipsis}`);
if (!repoPath) return undefined;
if (!args.ref1) {
let placeHolder;

+ 3
- 4
src/commands/diffDirectory.ts Ver ficheiro

@ -1,12 +1,11 @@
'use strict';
import { CancellationTokenSource, commands, TextEditor, Uri, window } from 'vscode';
import { ActiveEditorCommand, Commands, getCommandUri } from './common';
import { ActiveEditorCommand, Commands, getCommandUri, getRepoPathOrActiveOrPrompt } from './common';
import { CommandContext, isCommandViewContextWithRef } from '../commands';
import { BuiltInCommands, GlyphChars } from '../constants';
import { Container } from '../container';
import { ComparisonResultsNode } from '../views/explorerNodes';
import { Logger } from '../logger';
import { Messages } from '../messages';
import { BranchesAndTagsQuickPick, CommandQuickPickItem } from '../quickPicks/quickPicks';
export interface DiffDirectoryCommandArgs {
@ -51,8 +50,8 @@ export class DiffDirectoryCommand extends ActiveEditorCommand {
let progressCancellation: CancellationTokenSource | undefined;
try {
const repoPath = await Container.git.getRepoPath(uri);
if (!repoPath) return Messages.showNoRepositoryWarningMessage(`Unable to open directory compare`);
const repoPath = await getRepoPathOrActiveOrPrompt(uri, editor, `Compare directory in which repository${GlyphChars.Ellipsis}`);
if (!repoPath) return undefined;
if (!args.ref1) {
args = { ...args };

+ 2
- 2
src/commands/diffLineWithPrevious.ts Ver ficheiro

@ -22,13 +22,13 @@ export class DiffLineWithPreviousCommand extends ActiveEditorCommand {
async execute(editor?: TextEditor, uri?: Uri, args: DiffLineWithPreviousCommandArgs = {}): Promise<any> {
uri = getCommandUri(uri, editor);
if (uri === undefined) return undefined;
if (uri == null) return undefined;
const gitUri = await GitUri.fromUri(uri);
args = { ...args };
if (args.line === undefined) {
args.line = editor === undefined ? 0 : editor.selection.active.line;
args.line = editor == null ? 0 : editor.selection.active.line;
}
if (args.commit === undefined || GitService.isUncommitted(args.commit.sha)) {

+ 2
- 2
src/commands/diffLineWithWorking.ts Ver ficheiro

@ -22,13 +22,13 @@ export class DiffLineWithWorkingCommand extends ActiveEditorCommand {
async execute(editor?: TextEditor, uri?: Uri, args: DiffLineWithWorkingCommandArgs = {}): Promise<any> {
uri = getCommandUri(uri, editor);
if (uri === undefined) return undefined;
if (uri == null) return undefined;
const gitUri = await GitUri.fromUri(uri);
args = { ...args };
if (args.line === undefined) {
args.line = editor === undefined ? 0 : editor.selection.active.line;
args.line = editor == null ? 0 : editor.selection.active.line;
}
if (args.commit === undefined || GitService.isUncommitted(args.commit.sha)) {

+ 2
- 2
src/commands/diffWithBranch.ts Ver ficheiro

@ -25,11 +25,11 @@ export class DiffWithBranchCommand extends ActiveEditorCommand {
async execute(editor?: TextEditor, uri?: Uri, args: DiffWithBranchCommandArgs = {}): Promise<any> {
uri = getCommandUri(uri, editor);
if (uri === undefined) return undefined;
if (uri == null) return undefined;
args = { ...args };
if (args.line === undefined) {
args.line = editor === undefined ? 0 : editor.selection.active.line;
args.line = editor == null ? 0 : editor.selection.active.line;
}
const gitUri = await GitUri.fromUri(uri);

+ 2
- 2
src/commands/diffWithNext.ts Ver ficheiro

@ -24,11 +24,11 @@ export class DiffWithNextCommand extends ActiveEditorCommand {
async execute(editor?: TextEditor, uri?: Uri, args: DiffWithNextCommandArgs = {}): Promise<any> {
uri = getCommandUri(uri, editor);
if (uri === undefined) return undefined;
if (uri == null) return undefined;
args = { ...args };
if (args.line === undefined) {
args.line = editor === undefined ? 0 : editor.selection.active.line;
args.line = editor == null ? 0 : editor.selection.active.line;
}
const gitUri = await GitUri.fromUri(uri);

+ 2
- 2
src/commands/diffWithPrevious.ts Ver ficheiro

@ -33,11 +33,11 @@ export class DiffWithPreviousCommand extends ActiveEditorCommand {
async execute(editor?: TextEditor, uri?: Uri, args: DiffWithPreviousCommandArgs = {}): Promise<any> {
uri = getCommandUri(uri, editor);
if (uri === undefined) return undefined;
if (uri == null) return undefined;
args = { ...args };
if (args.line === undefined) {
args.line = editor === undefined ? 0 : editor.selection.active.line;
args.line = editor == null ? 0 : editor.selection.active.line;
}
if (args.commit === undefined || !args.commit.isFile) {

+ 2
- 2
src/commands/diffWithRevision.ts Ver ficheiro

@ -26,11 +26,11 @@ export class DiffWithRevisionCommand extends ActiveEditorCommand {
async execute(editor?: TextEditor, uri?: Uri, args: DiffWithRevisionCommandArgs = {}): Promise<any> {
uri = getCommandUri(uri, editor);
if (uri === undefined) return undefined;
if (uri == null) return undefined;
args = { ...args };
if (args.line === undefined) {
args.line = editor === undefined ? 0 : editor.selection.active.line;
args.line = editor == null ? 0 : editor.selection.active.line;
}
const gitUri = await GitUri.fromUri(uri);

+ 2
- 2
src/commands/diffWithWorking.ts Ver ficheiro

@ -22,13 +22,13 @@ export class DiffWithWorkingCommand extends ActiveEditorCommand {
async execute(editor?: TextEditor, uri?: Uri, args: DiffWithWorkingCommandArgs = {}): Promise<any> {
uri = getCommandUri(uri, editor);
if (uri === undefined) return undefined;
if (uri == null) return undefined;
const gitUri = await GitUri.fromUri(uri);
args = { ...args };
if (args.line === undefined) {
args.line = editor === undefined ? 0 : editor.selection.active.line;
args.line = editor == null ? 0 : editor.selection.active.line;
}
if (args.commit === undefined || GitService.isUncommitted(args.commit.sha)) {

+ 7
- 8
src/commands/externalDiff.ts Ver ficheiro

@ -1,12 +1,11 @@
'use strict';
import { Arrays } from '../system';
import { commands, SourceControlResourceState, Uri, window } from 'vscode';
import { Command, Commands } from './common';
import { BuiltInCommands } from '../constants';
import { Command, Commands, getRepoPathOrActiveOrPrompt } from './common';
import { BuiltInCommands, GlyphChars } from '../constants';
import { CommandContext } from '../commands';
import { Container } from '../container';
import { Logger } from '../logger';
import { Messages } from '../messages';
enum Status {
INDEX_MODIFIED,
@ -84,12 +83,12 @@ export class ExternalDiffCommand extends Command {
async execute(args: ExternalDiffCommandArgs = {}) {
try {
const repoPath = await Container.git.getRepoPath(undefined);
if (!repoPath) return Messages.showNoRepositoryWarningMessage(`Unable to open external file compare`);
const repoPath = await getRepoPathOrActiveOrPrompt(undefined, undefined, `Open changes from which repository${GlyphChars.Ellipsis}`);
if (!repoPath) return undefined;
const tool = await Container.git.getDiffTool(repoPath);
if (tool === undefined) {
const result = await window.showWarningMessage(`Unable to open external file compare because there is no Git diff tool configured`, 'View Git Docs');
const result = await window.showWarningMessage(`Unable to open changes in diff tool because there is no Git diff tool configured`, 'View Git Docs');
if (!result) return undefined;
return commands.executeCommand(BuiltInCommands.Open, Uri.parse('https://git-scm.com/docs/git-config#git-config-difftool'));
@ -97,7 +96,7 @@ export class ExternalDiffCommand extends Command {
if (args.files === undefined) {
const status = await Container.git.getStatusForRepo(repoPath);
if (status === undefined) return window.showWarningMessage(`Unable to open external file compare`);
if (status === undefined) return window.showWarningMessage(`Unable to open changes in diff tool`);
args.files = [];
@ -120,7 +119,7 @@ export class ExternalDiffCommand extends Command {
}
catch (ex) {
Logger.error(ex, 'ExternalDiffCommand');
return window.showErrorMessage(`Unable to open external file compare. See output channel for more details`);
return window.showErrorMessage(`Unable to open changes in diff tool. See output channel for more details`);
}
}
}

+ 3
- 3
src/commands/openBranchInRemote.ts Ver ficheiro

@ -1,6 +1,6 @@
'use strict';
import { commands, TextEditor, Uri, window } from 'vscode';
import { ActiveEditorCommand, CommandContext, Commands, getCommandUri, isCommandViewContextWithBranch } from './common';
import { ActiveEditorCommand, CommandContext, Commands, getCommandUri, getRepoPathOrActiveOrPrompt, isCommandViewContextWithBranch } from './common';
import { GlyphChars } from '../constants';
import { Container } from '../container';
import { GitUri } from '../gitService';
@ -34,7 +34,7 @@ export class OpenBranchInRemoteCommand extends ActiveEditorCommand {
const gitUri = uri && await GitUri.fromUri(uri);
const repoPath = gitUri === undefined ? Container.git.getHighlanderRepoPath() : gitUri.repoPath;
const repoPath = await getRepoPathOrActiveOrPrompt(gitUri, editor, `Open branch in remote for which repository${GlyphChars.Ellipsis}`);
if (!repoPath) return undefined;
try {
@ -43,7 +43,7 @@ export class OpenBranchInRemoteCommand extends ActiveEditorCommand {
const branches = await Container.git.getBranches(repoPath);
const pick = await BranchesQuickPick.show(branches, `Show history for branch${GlyphChars.Ellipsis}`);
const pick = await BranchesQuickPick.show(branches, `Open which branch in remote${GlyphChars.Ellipsis}`);
if (pick === undefined) return undefined;
if (pick instanceof CommandQuickPickItem) return undefined;

+ 3
- 2
src/commands/openBranchesInRemote.ts Ver ficheiro

@ -1,6 +1,7 @@
'use strict';
import { commands, TextEditor, Uri, window } from 'vscode';
import { ActiveEditorCommand, CommandContext, Commands, getCommandUri, isCommandViewContextWithRemote } from './common';
import { ActiveEditorCommand, CommandContext, Commands, getCommandUri, getRepoPathOrActiveOrPrompt, isCommandViewContextWithRemote } from './common';
import { GlyphChars } from '../constants';
import { Container } from '../container';
import { GitUri } from '../gitService';
import { Logger } from '../logger';
@ -30,7 +31,7 @@ export class OpenBranchesInRemoteCommand extends ActiveEditorCommand {
const gitUri = uri && await GitUri.fromUri(uri);
const repoPath = gitUri === undefined ? Container.git.getHighlanderRepoPath() : gitUri.repoPath;
const repoPath = await getRepoPathOrActiveOrPrompt(gitUri, editor, `Open branches in remote for which repository${GlyphChars.Ellipsis}`);
if (!repoPath) return undefined;
try {

+ 4
- 4
src/commands/openChangedFiles.ts Ver ficheiro

@ -1,10 +1,10 @@
'use strict';
import { Arrays } from '../system';
import { TextDocumentShowOptions, TextEditor, Uri, window } from 'vscode';
import { ActiveEditorCommand, Commands, getCommandUri, openEditor } from './common';
import { ActiveEditorCommand, Commands, getCommandUri, getRepoPathOrActiveOrPrompt, openEditor } from './common';
import { GlyphChars } from '../constants';
import { Container } from '../container';
import { Logger } from '../logger';
import { Messages } from '../messages';
export interface OpenChangedFilesCommandArgs {
uris?: Uri[];
@ -23,8 +23,8 @@ export class OpenChangedFilesCommand extends ActiveEditorCommand {
if (args.uris === undefined) {
args = { ...args };
const repoPath = await Container.git.getRepoPath(uri);
if (!repoPath) return Messages.showNoRepositoryWarningMessage(`Unable to open changed files`);
const repoPath = await getRepoPathOrActiveOrPrompt(uri, editor, `Open changed files in which repository${GlyphChars.Ellipsis}`);
if (!repoPath) return undefined;
const status = await Container.git.getStatusForRepo(repoPath);
if (status === undefined) return window.showWarningMessage(`Unable to open changed files`);

+ 2
- 2
src/commands/openCommitInRemote.ts Ver ficheiro

@ -38,13 +38,13 @@ export class OpenCommitInRemoteCommand extends ActiveEditorCommand {
async execute(editor?: TextEditor, uri?: Uri, args: OpenCommitInRemoteCommandArgs = {}) {
uri = getCommandUri(uri, editor);
if (uri === undefined) return undefined;
if (uri == null) return undefined;
const gitUri = await GitUri.fromUri(uri);
if (!gitUri.repoPath) return undefined;
try {
if (args.sha === undefined) {
const blameline = editor === undefined ? 0 : editor.selection.active.line;
const blameline = editor == null ? 0 : editor.selection.active.line;
if (blameline < 0) return undefined;
const blame = editor && editor.document && editor.document.isDirty

+ 2
- 2
src/commands/openFileInRemote.ts Ver ficheiro

@ -32,7 +32,7 @@ export class OpenFileInRemoteCommand extends ActiveEditorCommand {
async execute(editor?: TextEditor, uri?: Uri, args: OpenFileInRemoteCommandArgs = { range: true }) {
uri = getCommandUri(uri, editor);
if (uri === undefined) return undefined;
if (uri == null) return undefined;
const gitUri = await GitUri.fromUri(uri);
if (!gitUri.repoPath) return undefined;
@ -46,7 +46,7 @@ export class OpenFileInRemoteCommand extends ActiveEditorCommand {
try {
const remotes = await Container.git.getRemotes(gitUri.repoPath);
const range = (args.range && editor !== undefined)
const range = (args.range && editor != null)
? new Range(editor.selection.start.with({ line: editor.selection.start.line + 1 }), editor.selection.end.with({ line: editor.selection.end.line + 1 }))
: undefined;

+ 3
- 3
src/commands/openFileRevision.ts Ver ficheiro

@ -49,15 +49,15 @@ export class OpenFileRevisionCommand extends ActiveEditorCommand {
async execute(editor: TextEditor, uri?: Uri, args: OpenFileRevisionCommandArgs = {}) {
args = { ...args };
if (args.line === undefined) {
args.line = editor === undefined ? 0 : editor.selection.active.line;
args.line = editor == null ? 0 : editor.selection.active.line;
}
let progressCancellation: CancellationTokenSource | undefined;
try {
if (args.uri === undefined) {
if (args.uri == null) {
uri = getCommandUri(uri, editor);
if (uri === undefined) return undefined;
if (uri == null) return undefined;
const gitUri = await GitUri.fromUri(uri);

+ 3
- 2
src/commands/openRepoInRemote.ts Ver ficheiro

@ -1,6 +1,7 @@
'use strict';
import { commands, TextEditor, Uri, window } from 'vscode';
import { ActiveEditorCommand, CommandContext, Commands, getCommandUri, isCommandViewContextWithRemote } from './common';
import { ActiveEditorCommand, CommandContext, Commands, getCommandUri, getRepoPathOrActiveOrPrompt, isCommandViewContextWithRemote } from './common';
import { GlyphChars } from '../constants';
import { Container } from '../container';
import { GitUri } from '../gitService';
import { Logger } from '../logger';
@ -30,7 +31,7 @@ export class OpenRepoInRemoteCommand extends ActiveEditorCommand {
const gitUri = uri && await GitUri.fromUri(uri);
const repoPath = gitUri === undefined ? Container.git.getHighlanderRepoPath() : gitUri.repoPath;
const repoPath = await getRepoPathOrActiveOrPrompt(gitUri, editor, `Open which repository in remote${GlyphChars.Ellipsis}`);
if (!repoPath) return undefined;
try {

+ 3
- 3
src/commands/openWorkingFile.ts Ver ficheiro

@ -23,13 +23,13 @@ export class OpenWorkingFileCommand extends ActiveEditorCommand {
async execute(editor: TextEditor, uri?: Uri, args: OpenWorkingFileCommandArgs = {}) {
args = { ...args };
if (args.line === undefined) {
args.line = editor === undefined ? 0 : editor.selection.active.line;
args.line = editor == null ? 0 : editor.selection.active.line;
}
try {
if (args.uri === undefined) {
if (args.uri == null) {
uri = getCommandUri(uri, editor);
if (uri === undefined) return undefined;
if (uri == null) return undefined;
args.uri = await GitUri.fromUri(uri);
if (args.uri instanceof GitUri && args.uri.sha) {

+ 6
- 12
src/commands/showCommitSearch.ts Ver ficheiro

@ -1,12 +1,12 @@
'use strict';
import { Strings } from '../system';
import { commands, InputBoxOptions, TextEditor, Uri, window } from 'vscode';
import { ActiveEditorCachedCommand, Commands, getCommandUri } from './common';
import { ActiveEditorCachedCommand, Commands, getCommandUri, getRepoPathOrActiveOrPrompt } from './common';
import { GlyphChars } from '../constants';
import { Container } from '../container';
import { GitRepoSearchBy, GitService, GitUri } from '../gitService';
import { Logger } from '../logger';
import { CommandQuickPickItem, CommitsQuickPick, RepositoriesQuickPick, ShowCommitsSearchInResultsQuickPickItem } from '../quickPicks/quickPicks';
import { CommandQuickPickItem, CommitsQuickPick, ShowCommitsSearchInResultsQuickPickItem } from '../quickPicks/quickPicks';
import { ShowQuickCommitDetailsCommandArgs } from './showQuickCommitDetails';
const searchByRegex = /^([@~=:#])/;
@ -35,16 +35,10 @@ export class ShowCommitSearchCommand extends ActiveEditorCachedCommand {
async execute(editor?: TextEditor, uri?: Uri, args: ShowCommitSearchCommandArgs = {}) {
uri = getCommandUri(uri, editor);
const gitUri = uri === undefined ? undefined : await GitUri.fromUri(uri);
const gitUri = uri && await GitUri.fromUri(uri);
let repoPath = gitUri === undefined ? Container.git.getHighlanderRepoPath() : gitUri.repoPath;
if (!repoPath) {
const pick = await RepositoriesQuickPick.show(`Search for commits in which repository${GlyphChars.Ellipsis}`, args.goBackCommand);
if (pick instanceof CommandQuickPickItem) return pick.execute();
if (pick === undefined) return args.goBackCommand === undefined ? undefined : args.goBackCommand.execute();
repoPath = pick.repoPath;
}
const repoPath = await getRepoPathOrActiveOrPrompt(gitUri, editor, `Search for commits in which repository${GlyphChars.Ellipsis}`, args.goBackCommand);
if (!repoPath) return undefined;
args = { ...args };
const originalArgs = { ...args };
@ -52,7 +46,7 @@ export class ShowCommitSearchCommand extends ActiveEditorCachedCommand {
if (!args.search || args.searchBy == null) {
try {
if (!args.search) {
if (editor !== undefined && gitUri !== undefined) {
if (editor != null && gitUri != null) {
const blameLine = await Container.git.getBlameForLine(gitUri, editor.selection.active.line);
if (blameLine !== undefined && !blameLine.commit.isUncommitted) {
args.search = `#${blameLine.commit.shortSha}`;

+ 13
- 5
src/commands/showQuickBranchHistory.ts Ver ficheiro

@ -1,12 +1,11 @@
'use strict';
import { Strings } from '../system';
import { commands, TextEditor, Uri, window } from 'vscode';
import { ActiveEditorCachedCommand, Commands, getCommandUri } from './common';
import { ActiveEditorCachedCommand, Commands, getCommandUri, getRepoPathOrActiveOrPrompt } from './common';
import { GlyphChars } from '../constants';
import { Container } from '../container';
import { GitLog, GitUri } from '../gitService';
import { Logger } from '../logger';
import { Messages } from '../messages';
import { BranchesQuickPick, BranchHistoryQuickPick, CommandQuickPickItem } from '../quickPicks/quickPicks';
import { ShowQuickCommitDetailsCommandArgs } from './showQuickCommitDetails';
@ -14,6 +13,7 @@ export interface ShowQuickBranchHistoryCommandArgs {
branch?: string;
log?: GitLog;
maxCount?: number;
repoPath?: string;
goBackCommand?: CommandQuickPickItem;
nextPageCommand?: CommandQuickPickItem;
@ -34,13 +34,21 @@ export class ShowQuickBranchHistoryCommand extends ActiveEditorCachedCommand {
let progressCancellation = args.branch === undefined ? undefined : BranchHistoryQuickPick.showProgress(args.branch);
try {
const repoPath = gitUri === undefined ? Container.git.getHighlanderRepoPath() : gitUri.repoPath;
if (!repoPath) return Messages.showNoRepositoryWarningMessage(`Unable to show branch history`);
const repoPath = args.repoPath || await getRepoPathOrActiveOrPrompt(gitUri, editor, `Show branch history in which repository${GlyphChars.Ellipsis}`);
if (!repoPath) return undefined;
if (args.branch === undefined) {
const branches = await Container.git.getBranches(repoPath);
const pick = await BranchesQuickPick.show(branches, `Show history for branch${GlyphChars.Ellipsis}`);
let goBackCommand;
if (!(await Container.git.getRepoPathOrActive(uri, editor))) {
goBackCommand = new CommandQuickPickItem({
label: `go back ${GlyphChars.ArrowBack}`,
description: `${Strings.pad(GlyphChars.Dash, 2, 3)} to which repository`
}, Commands.ShowQuickBranchHistory, [uri, args]);
}
const pick = await BranchesQuickPick.show(branches, `Show history for branch${GlyphChars.Ellipsis}`, { goBackCommand: goBackCommand });
if (pick === undefined) return undefined;
if (pick instanceof CommandQuickPickItem) return pick.execute();

+ 2
- 2
src/commands/showQuickCommitDetails.ts Ver ficheiro

@ -48,7 +48,7 @@ export class ShowQuickCommitDetailsCommand extends ActiveEditorCachedCommand {
async execute(editor?: TextEditor, uri?: Uri, args: ShowQuickCommitDetailsCommandArgs = {}) {
uri = getCommandUri(uri, editor);
if (uri === undefined) return undefined;
if (uri == null) return undefined;
const gitUri = await GitUri.fromUri(uri);
@ -57,7 +57,7 @@ export class ShowQuickCommitDetailsCommand extends ActiveEditorCachedCommand {
args = { ...args };
if (args.sha === undefined) {
if (editor === undefined) return undefined;
if (editor == null) return undefined;
const blameline = editor.selection.active.line;
if (blameline < 0) return undefined;

+ 2
- 2
src/commands/showQuickCommitFileDetails.ts Ver ficheiro

@ -48,7 +48,7 @@ export class ShowQuickCommitFileDetailsCommand extends ActiveEditorCachedCommand
async execute(editor?: TextEditor, uri?: Uri, args: ShowQuickCommitFileDetailsCommandArgs = {}) {
uri = getCommandUri(uri, editor);
if (uri === undefined) return undefined;
if (uri == null) return undefined;
let workingFileName = args.commit && args.commit.workingFileName;
@ -56,7 +56,7 @@ export class ShowQuickCommitFileDetailsCommand extends ActiveEditorCachedCommand
args = { ...args };
if (args.sha === undefined) {
if (editor === undefined) return undefined;
if (editor == null) return undefined;
const blameline = editor.selection.active.line;
if (blameline < 0) return undefined;

+ 5
- 4
src/commands/showQuickCurrentBranchHistory.ts Ver ficheiro

@ -1,9 +1,9 @@
'use strict';
import { commands, TextEditor, Uri, window } from 'vscode';
import { ActiveEditorCachedCommand, Commands, getCommandUri } from './common';
import { ActiveEditorCachedCommand, Commands, getCommandUri, getRepoPathOrActiveOrPrompt } from './common';
import { GlyphChars } from '../constants';
import { Container } from '../container';
import { Logger } from '../logger';
import { Messages } from '../messages';
import { CommandQuickPickItem } from '../quickPicks/quickPicks';
import { ShowQuickBranchHistoryCommandArgs } from './showQuickBranchHistory';
@ -21,8 +21,8 @@ export class ShowQuickCurrentBranchHistoryCommand extends ActiveEditorCachedComm
uri = getCommandUri(uri, editor);
try {
const repoPath = await Container.git.getRepoPath(uri);
if (!repoPath) return Messages.showNoRepositoryWarningMessage(`Unable to show branch history`);
const repoPath = await getRepoPathOrActiveOrPrompt(uri, editor, `Show current branch history for which repository${GlyphChars.Ellipsis}`);
if (!repoPath) return undefined;
const branch = await Container.git.getBranch(repoPath);
if (branch === undefined) return undefined;
@ -31,6 +31,7 @@ export class ShowQuickCurrentBranchHistoryCommand extends ActiveEditorCachedComm
uri,
{
branch: branch.name,
repoPath: repoPath,
goBackCommand: args.goBackCommand
} as ShowQuickBranchHistoryCommandArgs);
}

+ 1
- 1
src/commands/showQuickFileHistory.ts Ver ficheiro

@ -28,7 +28,7 @@ export class ShowQuickFileHistoryCommand extends ActiveEditorCachedCommand {
async execute(editor?: TextEditor, uri?: Uri, args: ShowQuickFileHistoryCommandArgs = {}) {
uri = getCommandUri(uri, editor);
if (uri === undefined) return commands.executeCommand(Commands.ShowQuickCurrentBranchHistory);
if (uri == null) return commands.executeCommand(Commands.ShowQuickCurrentBranchHistory);
const gitUri = await GitUri.fromUri(uri);

+ 4
- 4
src/commands/showQuickRepoStatus.ts Ver ficheiro

@ -1,9 +1,9 @@
'use strict';
import { TextEditor, Uri, window } from 'vscode';
import { ActiveEditorCachedCommand, Commands, getCommandUri } from './common';
import { ActiveEditorCachedCommand, Commands, getCommandUri, getRepoPathOrActiveOrPrompt } from './common';
import { GlyphChars } from '../constants';
import { Container } from '../container';
import { Logger } from '../logger';
import { Messages } from '../messages';
import { CommandQuickPickItem, RepoStatusQuickPick } from '../quickPicks/quickPicks';
export interface ShowQuickRepoStatusCommandArgs {
@ -20,8 +20,8 @@ export class ShowQuickRepoStatusCommand extends ActiveEditorCachedCommand {
uri = getCommandUri(uri, editor);
try {
const repoPath = await Container.git.getRepoPath(uri);
if (!repoPath) return Messages.showNoRepositoryWarningMessage(`Unable to show repository status`);
const repoPath = await getRepoPathOrActiveOrPrompt(uri, editor, `Show status for which repository${GlyphChars.Ellipsis}`);
if (!repoPath) return undefined;
const status = await Container.git.getStatusForRepo(repoPath);
if (status === undefined) return window.showWarningMessage(`Unable to show repository status`);

+ 3
- 4
src/commands/showQuickStashList.ts Ver ficheiro

@ -1,11 +1,10 @@
'use strict';
import { Strings } from '../system';
import { commands, TextEditor, Uri, window } from 'vscode';
import { ActiveEditorCachedCommand, Commands, getCommandUri } from './common';
import { ActiveEditorCachedCommand, Commands, getCommandUri, getRepoPathOrActiveOrPrompt } from './common';
import { GlyphChars } from '../constants';
import { Container } from '../container';
import { Logger } from '../logger';
import { Messages } from '../messages';
import { CommandQuickPickItem, StashListQuickPick } from '../quickPicks/quickPicks';
import { ShowQuickCommitDetailsCommandArgs } from './showQuickCommitDetails';
@ -25,8 +24,8 @@ export class ShowQuickStashListCommand extends ActiveEditorCachedCommand {
const progressCancellation = StashListQuickPick.showProgress('list');
try {
const repoPath = await Container.git.getRepoPath(uri);
if (!repoPath) return Messages.showNoRepositoryWarningMessage(`Unable to show stashed changes`);
const repoPath = await getRepoPathOrActiveOrPrompt(uri, editor, `Show stashed changes for which repository${GlyphChars.Ellipsis}`);
if (!repoPath) return undefined;
const stash = await Container.git.getStashList(repoPath);
if (stash === undefined) return window.showWarningMessage(`Unable to show stashed changes`);

+ 3
- 3
src/commands/toggleFileBlame.ts Ver ficheiro

@ -18,11 +18,11 @@ export class ToggleFileBlameCommand extends ActiveEditorCommand {
}
async execute(editor: TextEditor, uri?: Uri, args: ToggleFileBlameCommandArgs = {}): Promise<any> {
// if (editor === undefined) return undefined;
// if (editor == null) return undefined;
if (editor !== undefined) {
if (editor != null) {
// Handle the case where we are focused on a non-editor editor (output, debug console)
if (uri !== undefined && !UriComparer.equals(uri, editor.document.uri)) {
if (uri != null && !UriComparer.equals(uri, editor.document.uri)) {
const e = window.visibleTextEditors.find(e => UriComparer.equals(uri, e.document.uri));
if (e !== undefined) {
editor = e;

+ 2
- 2
src/constants.ts Ver ficheiro

@ -61,12 +61,12 @@ export enum DocumentSchemes {
export function getEditorIfActive(document: TextDocument): TextEditor | undefined {
const editor = window.activeTextEditor;
return (editor !== undefined && editor.document === document) ? editor : undefined;
return (editor != null && editor.document === document) ? editor : undefined;
}
export function isActiveDocument(document: TextDocument): boolean {
const editor = window.activeTextEditor;
return editor !== undefined && editor.document === document;
return editor != null && editor.document === document;
}
export function isTextEditor(editor: TextEditor): boolean {

+ 1
- 1
src/git/gitUri.ts Ver ficheiro

@ -40,7 +40,7 @@ export class GitUri extends ((Uri as any) as UriEx) {
constructor(uri: Uri, commit: IGitCommitInfo);
constructor(uri: Uri, repoPath: string | undefined);
constructor(uri?: Uri, commitOrRepoPath?: IGitCommitInfo | string) {
if (uri === undefined) {
if (uri == null) {
super();
return;

+ 19
- 11
src/gitService.ts Ver ficheiro

@ -386,18 +386,19 @@ export class GitService extends Disposable {
}
async getActiveRepoPath(editor?: TextEditor): Promise<string | undefined> {
if (editor === undefined) {
const repoPath = this.getHighlanderRepoPath();
if (repoPath !== undefined) return repoPath;
}
editor = editor || window.activeTextEditor;
if (editor === undefined) return undefined;
const doc = await Container.tracker.getOrAdd(editor.document.uri);
if (doc === undefined) return undefined;
let repoPath;
if (editor != null) {
const doc = await Container.tracker.getOrAdd(editor.document.uri);
if (doc !== undefined) {
repoPath = doc.uri.repoPath;
}
}
if (repoPath != null) return repoPath;
return doc.uri.repoPath;
return this.getHighlanderRepoPath();
}
getHighlanderRepoPath(): string | undefined {
@ -1188,7 +1189,7 @@ export class GitService extends Disposable {
async getRepoPath(filePath: string, options?: { ref?: string }): Promise<string | undefined>;
async getRepoPath(uri: Uri | undefined, options?: { ref?: string }): Promise<string | undefined>;
async getRepoPath(filePathOrUri: string | Uri | undefined, options: { ref?: string } = {}): Promise<string | undefined> {
if (filePathOrUri === undefined) return await this.getActiveRepoPath();
if (filePathOrUri == null) return await this.getActiveRepoPath();
if (filePathOrUri instanceof GitUri) return filePathOrUri.repoPath;
// Don't save the tracking info to the cache, because we could be looking in the wrong place (e.g. looking in the root when the file is in a submodule)
@ -1237,6 +1238,13 @@ export class GitService extends Disposable {
}
}
async getRepoPathOrActive(uri: Uri | undefined, editor: TextEditor | undefined) {
const repoPath = await Container.git.getRepoPath(uri);
if (repoPath) return repoPath;
return Container.git.getActiveRepoPath(editor);
}
async getRepositories(): Promise<Iterable<Repository>> {
const repositoryTree = await this.getRepositoryTree();
return repositoryTree.values();
@ -1470,7 +1478,7 @@ export class GitService extends Disposable {
Logger.log(`resolveReference('${repoPath}', '${ref}', '${uri && uri.toString()}')`);
if (uri === undefined) return (await Git.revparse(repoPath, ref)) || ref;
if (uri == null) return (await Git.revparse(repoPath, ref)) || ref;
return (await Git.log_resolve(repoPath, Strings.normalizePath(path.relative(repoPath, uri.fsPath)), ref)) || ref;
}

+ 1
- 1
src/views/gitExplorer.ts Ver ficheiro

@ -367,7 +367,7 @@ export class GitExplorer extends Disposable implements TreeDataProvider
static async getHistoryNode(explorer: Explorer, editor: TextEditor | undefined, root: ExplorerNode | undefined): Promise<ExplorerNode | undefined> {
// If we have no active editor, or no visible editors, or no trackable visible editors reset the view
if (editor === undefined || window.visibleTextEditors.length === 0 || !window.visibleTextEditors.some(e => e.document && Container.git.isTrackable(e.document.uri))) return undefined;
if (editor == null || window.visibleTextEditors.length === 0 || !window.visibleTextEditors.some(e => e.document && Container.git.isTrackable(e.document.uri))) return undefined;
// If we do have a visible trackable editor, don't change from the last state (avoids issues when focus switches to the problems/output/debug console panes)
if (editor.document === undefined || !Container.git.isTrackable(editor.document.uri)) return root;

Carregando…
Cancelar
Guardar