Browse Source

Passes container into all commands

Should help with eventual testing
main
Eric Amodio 3 years ago
parent
commit
e61e8cdd44
82 changed files with 389 additions and 382 deletions
  1. +3
    -3
      src/commands/addAuthors.ts
  2. +3
    -3
      src/commands/browseRepoAtRevision.ts
  3. +3
    -3
      src/commands/closeUnchangedFiles.ts
  4. +3
    -3
      src/commands/closeView.ts
  5. +3
    -6
      src/commands/common.ts
  6. +4
    -4
      src/commands/compareWith.ts
  7. +3
    -3
      src/commands/copyCurrentBranch.ts
  8. +7
    -7
      src/commands/copyMessageToClipboard.ts
  9. +7
    -11
      src/commands/copyShaToClipboard.ts
  10. +3
    -3
      src/commands/createPullRequestOnRemote.ts
  11. +3
    -3
      src/commands/diffLineWithPrevious.ts
  12. +5
    -5
      src/commands/diffLineWithWorking.ts
  13. +7
    -7
      src/commands/diffWith.ts
  14. +3
    -3
      src/commands/diffWithNext.ts
  15. +3
    -3
      src/commands/diffWithPrevious.ts
  16. +4
    -4
      src/commands/diffWithRevision.ts
  17. +4
    -4
      src/commands/diffWithRevisionFrom.ts
  18. +5
    -10
      src/commands/diffWithWorking.ts
  19. +8
    -9
      src/commands/externalDiff.ts
  20. +4
    -4
      src/commands/git/branch.ts
  21. +5
    -5
      src/commands/git/cherry-pick.ts
  22. +9
    -7
      src/commands/git/coauthors.ts
  23. +5
    -5
      src/commands/git/fetch.ts
  24. +8
    -7
      src/commands/git/log.ts
  25. +6
    -6
      src/commands/git/merge.ts
  26. +5
    -5
      src/commands/git/pull.ts
  27. +6
    -6
      src/commands/git/push.ts
  28. +7
    -7
      src/commands/git/rebase.ts
  29. +5
    -5
      src/commands/git/reset.ts
  30. +5
    -5
      src/commands/git/revert.ts
  31. +9
    -8
      src/commands/git/search.ts
  32. +5
    -8
      src/commands/git/show.ts
  33. +9
    -8
      src/commands/git/stash.ts
  34. +4
    -4
      src/commands/git/status.ts
  35. +5
    -5
      src/commands/git/switch.ts
  36. +4
    -4
      src/commands/git/tag.ts
  37. +32
    -29
      src/commands/gitCommands.ts
  38. +4
    -4
      src/commands/inviteToLiveShare.ts
  39. +3
    -2
      src/commands/logging.ts
  40. +3
    -3
      src/commands/openAssociatedPullRequestOnRemote.ts
  41. +2
    -1
      src/commands/openBranchOnRemote.ts
  42. +2
    -1
      src/commands/openBranchesOnRemote.ts
  43. +3
    -3
      src/commands/openChangedFiles.ts
  44. +4
    -4
      src/commands/openCommitOnRemote.ts
  45. +2
    -1
      src/commands/openComparisonOnRemote.ts
  46. +2
    -1
      src/commands/openDirectoryCompare.ts
  47. +5
    -5
      src/commands/openFileAtRevision.ts
  48. +3
    -3
      src/commands/openFileAtRevisionFrom.ts
  49. +4
    -4
      src/commands/openFileFromRemote.ts
  50. +5
    -5
      src/commands/openFileOnRemote.ts
  51. +2
    -1
      src/commands/openIssueOnRemote.ts
  52. +4
    -4
      src/commands/openOnRemote.ts
  53. +4
    -4
      src/commands/openPullRequestOnRemote.ts
  54. +2
    -1
      src/commands/openRepoOnRemote.ts
  55. +3
    -3
      src/commands/openRevisionFile.ts
  56. +4
    -4
      src/commands/openWorkingFile.ts
  57. +3
    -2
      src/commands/quickCommand.ts
  58. +5
    -5
      src/commands/rebaseEditor.ts
  59. +2
    -1
      src/commands/refreshHover.ts
  60. +10
    -10
      src/commands/remoteProviders.ts
  61. +7
    -7
      src/commands/repositories.ts
  62. +2
    -1
      src/commands/resetAvatarCache.ts
  63. +2
    -1
      src/commands/resetSuppressedWarnings.ts
  64. +3
    -3
      src/commands/searchCommits.ts
  65. +2
    -1
      src/commands/setViewsLayout.ts
  66. +4
    -4
      src/commands/showCommitsInView.ts
  67. +2
    -1
      src/commands/showLastQuickPick.ts
  68. +3
    -3
      src/commands/showQuickBranchHistory.ts
  69. +4
    -4
      src/commands/showQuickCommit.ts
  70. +5
    -5
      src/commands/showQuickCommitFile.ts
  71. +3
    -3
      src/commands/showQuickFileHistory.ts
  72. +2
    -1
      src/commands/showQuickRepoStatus.ts
  73. +2
    -1
      src/commands/showQuickStashList.ts
  74. +13
    -13
      src/commands/showView.ts
  75. +2
    -1
      src/commands/stashApply.ts
  76. +6
    -6
      src/commands/stashSave.ts
  77. +12
    -15
      src/commands/switchMode.ts
  78. +3
    -3
      src/commands/toggleCodeLens.ts
  79. +11
    -10
      src/commands/toggleFileAnnotations.ts
  80. +3
    -3
      src/commands/toggleLineBlame.ts
  81. +1
    -1
      src/extension.ts
  82. +2
    -1
      src/quickpicks/gitQuickPickItems.ts

+ 3
- 3
src/commands/addAuthors.ts View File

@ -1,19 +1,19 @@
'use strict';
import { SourceControl } from 'vscode';
import { Container } from '../container';
import type { Container } from '../container';
import { command, Command, Commands } from './common';
import { executeGitCommand } from './gitCommands';
@command()
export class AddAuthorsCommand extends Command {
constructor() {
constructor(private readonly container: Container) {
super(Commands.AddAuthors);
}
async execute(sourceControl: SourceControl) {
let repo;
if (sourceControl?.rootUri != null) {
repo = await Container.instance.git.getRepository(sourceControl.rootUri);
repo = await this.container.git.getRepository(sourceControl.rootUri);
}
return executeGitCommand({

+ 3
- 3
src/commands/browseRepoAtRevision.ts View File

@ -1,7 +1,7 @@
'use strict';
import { commands, TextEditor, Uri } from 'vscode';
import { BuiltInCommands } from '../constants';
import { Container } from '../container';
import type { Container } from '../container';
import { toGitLensFSUri } from '../git/fsProvider';
import { GitUri } from '../git/gitUri';
import { Logger } from '../logger';
@ -26,7 +26,7 @@ export interface BrowseRepoAtRevisionCommandArgs {
@command()
export class BrowseRepoAtRevisionCommand extends ActiveEditorCommand {
constructor() {
constructor(private readonly container: Container) {
super([
Commands.BrowseRepoAtRevision,
Commands.BrowseRepoAtRevisionInNewWindow,
@ -66,7 +66,7 @@ export class BrowseRepoAtRevisionCommand extends ActiveEditorCommand {
if (gitUri.sha == null) return;
const sha = args?.before
? await Container.instance.git.resolveReference(gitUri.repoPath!, `${gitUri.sha}^`)
? await this.container.git.resolveReference(gitUri.repoPath!, `${gitUri.sha}^`)
: gitUri.sha;
uri = toGitLensFSUri(sha, gitUri.repoPath!);
gitUri = GitUri.fromRevisionUri(uri);

+ 3
- 3
src/commands/closeUnchangedFiles.ts View File

@ -2,7 +2,7 @@
import { commands, TextEditor, Uri, window } from 'vscode';
import { TextEditorComparer, UriComparer } from '../comparers';
import { BuiltInCommands } from '../constants';
import { Container } from '../container';
import type { Container } from '../container';
import { Logger } from '../logger';
import { Messages } from '../messages';
import { Functions } from '../system';
@ -16,7 +16,7 @@ export interface CloseUnchangedFilesCommandArgs {
export class CloseUnchangedFilesCommand extends Command {
private _onEditorChangedFn: ((editor: TextEditor | undefined) => void) | undefined;
constructor() {
constructor(private readonly container: Container) {
super(Commands.CloseUnchangedFiles);
}
@ -28,7 +28,7 @@ export class CloseUnchangedFilesCommand extends Command {
const repoPath = await getRepoPathOrPrompt('Close All Unchanged Files');
if (!repoPath) return;
const status = await Container.instance.git.getStatusForRepo(repoPath);
const status = await this.container.git.getStatusForRepo(repoPath);
if (status == null) {
void window.showWarningMessage('Unable to close unchanged files');

+ 3
- 3
src/commands/closeView.ts View File

@ -1,11 +1,11 @@
'use strict';
import { ContextKeys, setContext, SyncedState } from '../constants';
import { Container } from '../container';
import type { Container } from '../container';
import { command, Command, CommandContext, Commands } from './common';
@command()
export class CloseViewCommand extends Command {
constructor() {
constructor(private readonly container: Container) {
super([Commands.CloseWelcomeView]);
}
@ -16,7 +16,7 @@ export class CloseViewCommand extends Command {
async execute(command: Commands) {
switch (command) {
case Commands.CloseWelcomeView:
await Container.instance.context.globalState.update(SyncedState.WelcomeViewVisible, false);
await this.container.context.globalState.update(SyncedState.WelcomeViewVisible, false);
await setContext(ContextKeys.ViewsWelcomeVisible, false);
break;
}

+ 3
- 6
src/commands/common.ts View File

@ -2,7 +2,6 @@
import {
commands,
Disposable,
ExtensionContext,
GitTimelineItem,
SourceControlResourceGroup,
SourceControlResourceState,
@ -218,7 +217,7 @@ export function executeEditorCommand(command: Commands, uri: Uri | undefined,
}
interface CommandConstructor {
new (): Command;
new (container: Container): Command;
}
const registrableCommands: CommandConstructor[] = [];
@ -229,10 +228,8 @@ export function command(): ClassDecorator {
};
}
export function registerCommands(context: ExtensionContext): void {
for (const c of registrableCommands) {
context.subscriptions.push(new c());
}
export function registerCommands(container: Container): Disposable[] {
return registrableCommands.map(c => new c(container));
}
export function getCommandUri(uri?: Uri, editor?: TextEditor): Uri | undefined {

+ 4
- 4
src/commands/compareWith.ts View File

@ -1,6 +1,6 @@
'use strict';
import { TextEditor, Uri } from 'vscode';
import { Container } from '../container';
import type { Container } from '../container';
import { Logger } from '../logger';
import { Messages } from '../messages';
import {
@ -19,7 +19,7 @@ export interface CompareWithCommandArgs {
@command()
export class CompareWithCommand extends ActiveEditorCommand {
constructor() {
constructor(private readonly container: Container) {
super([
Commands.CompareWith,
Commands.CompareHeadWith,
@ -76,9 +76,9 @@ export class CompareWithCommand extends ActiveEditorCommand {
if (!repoPath) return;
if (args.ref1 != null && args.ref2 != null) {
void (await Container.instance.searchAndCompareView.compare(repoPath, args.ref1, args.ref2));
void (await this.container.searchAndCompareView.compare(repoPath, args.ref1, args.ref2));
} else {
Container.instance.searchAndCompareView.selectForCompare(repoPath, args.ref1, { prompt: true });
this.container.searchAndCompareView.selectForCompare(repoPath, args.ref1, { prompt: true });
}
} catch (ex) {
Logger.error(ex, 'CompareWithCommmand');

+ 3
- 3
src/commands/copyCurrentBranch.ts View File

@ -1,13 +1,13 @@
'use strict';
import { env, TextEditor, Uri, window } from 'vscode';
import { Container } from '../container';
import type { Container } from '../container';
import { GitUri } from '../git/gitUri';
import { Logger } from '../logger';
import { ActiveEditorCommand, command, Commands, getCommandUri, getRepoPathOrActiveOrPrompt } from './common';
@command()
export class CopyCurrentBranchCommand extends ActiveEditorCommand {
constructor() {
constructor(private readonly container: Container) {
super(Commands.CopyCurrentBranch);
}
@ -20,7 +20,7 @@ export class CopyCurrentBranchCommand extends ActiveEditorCommand {
if (!repoPath) return;
try {
const branch = await Container.instance.git.getBranch(repoPath);
const branch = await this.container.git.getBranch(repoPath);
if (branch?.name) {
await env.clipboard.writeText(branch.name);
}

+ 7
- 7
src/commands/copyMessageToClipboard.ts View File

@ -1,6 +1,6 @@
'use strict';
import { env, TextEditor, Uri } from 'vscode';
import { Container } from '../container';
import type { Container } from '../container';
import { GitUri } from '../git/gitUri';
import { Logger } from '../logger';
import { Messages } from '../messages';
@ -23,7 +23,7 @@ export interface CopyMessageToClipboardCommandArgs {
@command()
export class CopyMessageToClipboardCommand extends ActiveEditorCommand {
constructor() {
constructor(private readonly container: Container) {
super(Commands.CopyMessageToClipboard);
}
@ -53,10 +53,10 @@ export class CopyMessageToClipboardCommand extends ActiveEditorCommand {
let repoPath;
// If we don't have an editor then get the message of the last commit to the branch
if (uri == null) {
repoPath = await Container.instance.git.getActiveRepoPath(editor);
repoPath = await this.container.git.getActiveRepoPath(editor);
if (!repoPath) return;
const log = await Container.instance.git.getLog(repoPath, { limit: 1 });
const log = await this.container.git.getLog(repoPath, { limit: 1 });
if (log == null) return;
args.message = Iterables.first(log.commits.values()).message;
@ -70,12 +70,12 @@ export class CopyMessageToClipboardCommand extends ActiveEditorCommand {
try {
const blame = editor?.document.isDirty
? await Container.instance.git.getBlameForLineContents(
? await this.container.git.getBlameForLineContents(
gitUri,
blameline,
editor.document.getText(),
)
: await Container.instance.git.getBlameForLine(gitUri, blameline);
: await this.container.git.getBlameForLine(gitUri, blameline);
if (blame == null) return;
if (blame.commit.isUncommitted) return;
@ -93,7 +93,7 @@ export class CopyMessageToClipboardCommand extends ActiveEditorCommand {
}
// Get the full commit message -- since blame only returns the summary
const commit = await Container.instance.git.getCommit(repoPath!, args.sha);
const commit = await this.container.git.getCommit(repoPath!, args.sha);
if (commit == null) return;
args.message = commit.message;

+ 7
- 11
src/commands/copyShaToClipboard.ts View File

@ -1,6 +1,6 @@
'use strict';
import { env, TextEditor, Uri } from 'vscode';
import { Container } from '../container';
import type { Container } from '../container';
import { GitUri } from '../git/gitUri';
import { Logger } from '../logger';
import { Messages } from '../messages';
@ -22,14 +22,14 @@ export interface CopyShaToClipboardCommandArgs {
@command()
export class CopyShaToClipboardCommand extends ActiveEditorCommand {
constructor() {
constructor(private readonly container: Container) {
super(Commands.CopyShaToClipboard);
}
protected override preExecute(context: CommandContext, args?: CopyShaToClipboardCommandArgs) {
if (isCommandContextViewNodeHasCommit(context)) {
args = { ...args };
args.sha = Container.instance.config.advanced.abbreviateShaOnCopy
args.sha = this.container.config.advanced.abbreviateShaOnCopy
? context.node.commit.shortSha
: context.node.commit.sha;
return this.execute(context.editor, context.node.commit.uri, args);
@ -53,10 +53,10 @@ export class CopyShaToClipboardCommand extends ActiveEditorCommand {
try {
// 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.instance.git.getActiveRepoPath(editor);
const repoPath = await this.container.git.getActiveRepoPath(editor);
if (!repoPath) return;
const log = await Container.instance.git.getLog(repoPath, { limit: 1 });
const log = await this.container.git.getLog(repoPath, { limit: 1 });
if (log == null) return;
args.sha = Iterables.first(log.commits.values()).sha;
@ -67,12 +67,8 @@ export class CopyShaToClipboardCommand extends ActiveEditorCommand {
try {
const gitUri = await GitUri.fromUri(uri);
const blame = editor?.document.isDirty
? await Container.instance.git.getBlameForLineContents(
gitUri,
blameline,
editor.document.getText(),
)
: await Container.instance.git.getBlameForLine(gitUri, blameline);
? await this.container.git.getBlameForLineContents(gitUri, blameline, editor.document.getText())
: await this.container.git.getBlameForLine(gitUri, blameline);
if (blame == null) return;
args.sha = blame.commit.sha;

+ 3
- 3
src/commands/createPullRequestOnRemote.ts View File

@ -1,5 +1,5 @@
'use strict';
import { Container } from '../container';
import type { Container } from '../container';
import { GitRemote } from '../git/models';
import { RemoteProvider, RemoteResource, RemoteResourceType } from '../git/remotes/provider';
import { Command, command, Commands, executeCommand } from './common';
@ -16,14 +16,14 @@ export interface CreatePullRequestOnRemoteCommandArgs {
@command()
export class CreatePullRequestOnRemoteCommand extends Command {
constructor() {
constructor(private readonly container: Container) {
super(Commands.CreatePullRequestOnRemote);
}
async execute(args?: CreatePullRequestOnRemoteCommandArgs) {
if (args?.repoPath == null) return;
const repo = await Container.instance.git.getRepository(args.repoPath);
const repo = await this.container.git.getRepository(args.repoPath);
if (repo == null) return;
const compareRemote = await repo.getRemote(args.remote);

+ 3
- 3
src/commands/diffLineWithPrevious.ts View File

@ -1,6 +1,6 @@
'use strict';
import { TextDocumentShowOptions, TextEditor, Uri } from 'vscode';
import { Container } from '../container';
import type { Container } from '../container';
import { GitUri } from '../git/gitUri';
import { GitCommit } from '../git/models';
import { Logger } from '../logger';
@ -17,7 +17,7 @@ export interface DiffLineWithPreviousCommandArgs {
@command()
export class DiffLineWithPreviousCommand extends ActiveEditorCommand {
constructor() {
constructor(private readonly container: Container) {
super(Commands.DiffLineWithPrevious);
}
@ -33,7 +33,7 @@ export class DiffLineWithPreviousCommand extends ActiveEditorCommand {
const gitUri = args.commit != null ? GitUri.fromCommit(args.commit) : await GitUri.fromUri(uri);
try {
const diffUris = await Container.instance.git.getPreviousLineDiffUris(
const diffUris = await this.container.git.getPreviousLineDiffUris(
gitUri.repoPath!,
gitUri,
args.line,

+ 5
- 5
src/commands/diffLineWithWorking.ts View File

@ -1,6 +1,6 @@
'use strict';
import { TextDocumentShowOptions, TextEditor, Uri, window } from 'vscode';
import { Container } from '../container';
import type { Container } from '../container';
import { GitUri } from '../git/gitUri';
import { GitCommit, GitRevision } from '../git/models';
import { Logger } from '../logger';
@ -17,7 +17,7 @@ export interface DiffLineWithWorkingCommandArgs {
@command()
export class DiffLineWithWorkingCommand extends ActiveEditorCommand {
constructor() {
constructor(private readonly container: Container) {
super(Commands.DiffLineWithWorking);
}
@ -38,8 +38,8 @@ export class DiffLineWithWorkingCommand extends ActiveEditorCommand {
try {
const blame = editor?.document.isDirty
? await Container.instance.git.getBlameForLineContents(gitUri, blameline, editor.document.getText())
: await Container.instance.git.getBlameForLine(gitUri, blameline);
? await this.container.git.getBlameForLineContents(gitUri, blameline, editor.document.getText())
: await this.container.git.getBlameForLine(gitUri, blameline);
if (blame == null) {
void Messages.showFileNotUnderSourceControlWarningMessage('Unable to open compare');
@ -50,7 +50,7 @@ export class DiffLineWithWorkingCommand extends ActiveEditorCommand {
// If the line is uncommitted, change the previous commit
if (args.commit.isUncommitted) {
const status = await Container.instance.git.getStatusForFile(gitUri.repoPath!, gitUri.fsPath);
const status = await this.container.git.getStatusForFile(gitUri.repoPath!, gitUri.fsPath);
args.commit = args.commit.with({
sha: status?.indexStatus != null ? GitRevision.uncommittedStaged : args.commit.previousSha!,
fileName: args.commit.previousFileName!,

+ 7
- 7
src/commands/diffWith.ts View File

@ -1,7 +1,7 @@
'use strict';
import { commands, Range, TextDocumentShowOptions, Uri, ViewColumn } from 'vscode';
import { BuiltInCommands, GlyphChars } from '../constants';
import { Container } from '../container';
import type { Container } from '../container';
import { GitUri } from '../git/gitUri';
import { GitCommit, GitRevision } from '../git/models';
import { Logger } from '../logger';
@ -67,7 +67,7 @@ export class DiffWithCommand extends Command {
return super.getMarkdownCommandArgsCore<DiffWithCommandArgs>(Commands.DiffWith, args);
}
constructor() {
constructor(private readonly container: Container) {
super(Commands.DiffWith);
}
@ -88,10 +88,10 @@ export class DiffWithCommand extends Command {
let rhsSha = args.rhs.sha;
[args.lhs.sha, args.rhs.sha] = await Promise.all([
await Container.instance.git.resolveReference(args.repoPath, args.lhs.sha, args.lhs.uri, {
await this.container.git.resolveReference(args.repoPath, args.lhs.sha, args.lhs.uri, {
timeout: 100,
}),
await Container.instance.git.resolveReference(args.repoPath, args.rhs.sha, args.rhs.uri, {
await this.container.git.resolveReference(args.repoPath, args.rhs.sha, args.rhs.uri, {
timeout: 100,
}),
]);
@ -102,7 +102,7 @@ export class DiffWithCommand extends Command {
if (args.rhs.sha && args.rhs.sha !== GitRevision.deletedOrMissing) {
// Ensure that the file still exists in this commit
const status = await Container.instance.git.getFileStatusForCommit(
const status = await this.container.git.getFileStatusForCommit(
args.repoPath,
args.rhs.uri,
args.rhs.sha,
@ -119,8 +119,8 @@ export class DiffWithCommand extends Command {
}
const [lhs, rhs] = await Promise.all([
Container.instance.git.getVersionedUri(args.repoPath, args.lhs.uri.fsPath, args.lhs.sha),
Container.instance.git.getVersionedUri(args.repoPath, args.rhs.uri.fsPath, args.rhs.sha),
this.container.git.getVersionedUri(args.repoPath, args.lhs.uri.fsPath, args.lhs.sha),
this.container.git.getVersionedUri(args.repoPath, args.rhs.uri.fsPath, args.rhs.sha),
]);
let rhsSuffix = GitRevision.shorten(rhsSha, { strings: { uncommitted: 'Working Tree' } });

+ 3
- 3
src/commands/diffWithNext.ts View File

@ -1,6 +1,6 @@
'use strict';
import { Range, TextDocumentShowOptions, TextEditor, Uri } from 'vscode';
import { Container } from '../container';
import type { Container } from '../container';
import { GitUri } from '../git/gitUri';
import { GitLogCommit } from '../git/models';
import { Logger } from '../logger';
@ -19,7 +19,7 @@ export interface DiffWithNextCommandArgs {
@command()
export class DiffWithNextCommand extends ActiveEditorCommand {
constructor() {
constructor(private readonly container: Container) {
super([Commands.DiffWithNext, Commands.DiffWithNextInDiffLeft, Commands.DiffWithNextInDiffRight]);
}
@ -42,7 +42,7 @@ export class DiffWithNextCommand extends ActiveEditorCommand {
const gitUri = args.commit != null ? GitUri.fromCommit(args.commit) : await GitUri.fromUri(uri);
try {
const diffUris = await Container.instance.git.getNextDiffUris(
const diffUris = await this.container.git.getNextDiffUris(
gitUri.repoPath!,
gitUri,
gitUri.sha,

+ 3
- 3
src/commands/diffWithPrevious.ts View File

@ -1,6 +1,6 @@
'use strict';
import { TextDocumentShowOptions, TextEditor, Uri } from 'vscode';
import { Container } from '../container';
import type { Container } from '../container';
import { GitUri } from '../git/gitUri';
import { GitCommit, GitRevision } from '../git/models';
import { Logger } from '../logger';
@ -27,7 +27,7 @@ export interface DiffWithPreviousCommandArgs {
@command()
export class DiffWithPreviousCommand extends ActiveEditorCommand {
constructor() {
constructor(private readonly container: Container) {
super([Commands.DiffWithPrevious, Commands.DiffWithPreviousInDiffLeft, Commands.DiffWithPreviousInDiffRight]);
}
@ -83,7 +83,7 @@ export class DiffWithPreviousCommand extends ActiveEditorCommand {
// }
try {
const diffUris = await Container.instance.git.getPreviousDiffUris(
const diffUris = await this.container.git.getPreviousDiffUris(
gitUri.repoPath!,
gitUri,
gitUri.sha,

+ 4
- 4
src/commands/diffWithRevision.ts View File

@ -1,7 +1,7 @@
'use strict';
import { TextDocumentShowOptions, TextEditor, Uri } from 'vscode';
import { GlyphChars, quickPickTitleMaxChars } from '../constants';
import { Container } from '../container';
import type { Container } from '../container';
import { GitUri } from '../git/gitUri';
import { GitRevision } from '../git/models';
import { Logger } from '../logger';
@ -19,7 +19,7 @@ export interface DiffWithRevisionCommandArgs {
@command()
export class DiffWithRevisionCommand extends ActiveEditorCommand {
constructor() {
constructor(private readonly container: Container) {
super(Commands.DiffWithRevision);
}
@ -35,13 +35,13 @@ export class DiffWithRevisionCommand extends ActiveEditorCommand {
}
try {
const log = Container.instance.git
const log = this.container.git
.getLogForFile(gitUri.repoPath, gitUri.fsPath)
.then(
log =>
log ??
(gitUri.sha
? Container.instance.git.getLogForFile(gitUri.repoPath, gitUri.fsPath, { ref: gitUri.sha })
? this.container.git.getLogForFile(gitUri.repoPath, gitUri.fsPath, { ref: gitUri.sha })
: undefined),
);

+ 4
- 4
src/commands/diffWithRevisionFrom.ts View File

@ -1,7 +1,7 @@
'use strict';
import { TextDocumentShowOptions, TextEditor, Uri } from 'vscode';
import { GlyphChars, quickPickTitleMaxChars } from '../constants';
import { Container } from '../container';
import type { Container } from '../container';
import { GitUri } from '../git/gitUri';
import { GitReference, GitRevision } from '../git/models';
import { Messages } from '../messages';
@ -19,7 +19,7 @@ export interface DiffWithRevisionFromCommandArgs {
@command()
export class DiffWithRevisionFromCommand extends ActiveEditorCommand {
constructor() {
constructor(private readonly container: Container) {
super(Commands.DiffWithRevisionFrom);
}
@ -46,7 +46,7 @@ export class DiffWithRevisionFromCommand extends ActiveEditorCommand {
const title = `Open Changes with Stash${Strings.pad(GlyphChars.Dot, 2, 2)}`;
const pick = await StashPicker.show(
Container.instance.git.getStash(gitUri.repoPath),
this.container.git.getStash(gitUri.repoPath),
`${title}${gitUri.getFormattedFileName({ truncateTo: quickPickTitleMaxChars - title.length })}`,
'Choose a stash to compare with',
{
@ -81,7 +81,7 @@ export class DiffWithRevisionFromCommand extends ActiveEditorCommand {
let renamedTitle: string | undefined;
// Check to see if this file has been renamed
const files = await Container.instance.git.getDiffStatus(gitUri.repoPath, 'HEAD', ref, { filters: ['R', 'C'] });
const files = await this.container.git.getDiffStatus(gitUri.repoPath, 'HEAD', ref, { filters: ['R', 'C'] });
if (files != null) {
const fileName = normalizePath(relative(gitUri.repoPath, gitUri.fsPath));
const rename = files.find(s => s.fileName === fileName);

+ 5
- 10
src/commands/diffWithWorking.ts View File

@ -1,6 +1,6 @@
'use strict';
import { TextDocumentShowOptions, TextEditor, Uri, window } from 'vscode';
import { Container } from '../container';
import type { Container } from '../container';
import { GitUri } from '../git/gitUri';
import { GitRevision } from '../git/models';
import { Logger } from '../logger';
@ -17,7 +17,7 @@ export interface DiffWithWorkingCommandArgs {
@command()
export class DiffWithWorkingCommand extends ActiveEditorCommand {
constructor() {
constructor(private readonly container: Container) {
super([Commands.DiffWithWorking, Commands.DiffWithWorkingInDiffLeft, Commands.DiffWithWorkingInDiffRight]);
}
@ -38,12 +38,7 @@ export class DiffWithWorkingCommand extends ActiveEditorCommand {
if (args.inDiffRightEditor) {
try {
const diffUris = await Container.instance.git.getPreviousDiffUris(
gitUri.repoPath!,
gitUri,
gitUri.sha,
0,
);
const diffUris = await this.container.git.getPreviousDiffUris(gitUri.repoPath!, gitUri, gitUri.sha, 0);
gitUri = diffUris?.previous ?? gitUri;
} catch (ex) {
Logger.error(
@ -71,7 +66,7 @@ export class DiffWithWorkingCommand extends ActiveEditorCommand {
// If we are a fake "staged" sha, check the status
if (gitUri.isUncommittedStaged) {
const status = await Container.instance.git.getStatusForFile(gitUri.repoPath!, gitUri.fsPath);
const status = await this.container.git.getStatusForFile(gitUri.repoPath!, gitUri.fsPath);
if (status?.indexStatus != null) {
void (await executeCommand<DiffWithCommandArgs>(Commands.DiffWith, {
repoPath: gitUri.repoPath,
@ -93,7 +88,7 @@ export class DiffWithWorkingCommand extends ActiveEditorCommand {
uri = gitUri.toFileUri();
const workingUri = await Container.instance.git.getWorkingUri(gitUri.repoPath!, uri);
const workingUri = await this.container.git.getWorkingUri(gitUri.repoPath!, uri);
if (workingUri == null) {
void window.showWarningMessage('Unable to open compare. File has been deleted from the working tree');

+ 8
- 9
src/commands/externalDiff.ts View File

@ -2,7 +2,7 @@
import { env, SourceControlResourceState, Uri, window } from 'vscode';
import { ScmResource } from '../@types/vscode.git.resources';
import { ScmResourceGroupType, ScmStatus } from '../@types/vscode.git.resources.enums';
import { Container } from '../container';
import type { Container } from '../container';
import { GitUri } from '../git/gitUri';
import { GitRevision } from '../git/models';
import { Logger } from '../logger';
@ -31,7 +31,7 @@ export interface ExternalDiffCommandArgs {
@command()
export class ExternalDiffCommand extends Command {
constructor() {
constructor(private readonly container: Container) {
super([Commands.ExternalDiff, Commands.ExternalDiffAll]);
}
@ -92,7 +92,7 @@ export class ExternalDiffCommand extends Command {
const repoPath = await getRepoPathOrPrompt('Open All Changes (difftool)');
if (!repoPath) return undefined;
const status = await Container.instance.git.getStatusForRepo(repoPath);
const status = await this.container.git.getStatusForRepo(repoPath);
if (status == null) {
return window.showInformationMessage("The repository doesn't have any changes");
}
@ -130,11 +130,11 @@ export class ExternalDiffCommand extends Command {
const editor = window.activeTextEditor;
if (editor == null) return;
repoPath = await Container.instance.git.getRepoPathOrActive(undefined, editor);
repoPath = await this.container.git.getRepoPathOrActive(undefined, editor);
if (!repoPath) return;
const uri = editor.document.uri;
const status = await Container.instance.git.getStatusForFile(repoPath, uri.fsPath);
const status = await this.container.git.getStatusForFile(repoPath, uri.fsPath);
if (status == null) {
void window.showInformationMessage("The current file doesn't have any changes");
@ -150,13 +150,12 @@ export class ExternalDiffCommand extends Command {
args.files.push({ uri: status.uri, staged: false });
}
} else {
repoPath = await Container.instance.git.getRepoPath(args.files[0].uri.fsPath);
repoPath = await this.container.git.getRepoPath(args.files[0].uri.fsPath);
if (!repoPath) return;
}
const tool =
Container.instance.config.advanced.externalDiffTool ||
(await Container.instance.git.getDiffTool(repoPath));
this.container.config.advanced.externalDiffTool || (await this.container.git.getDiffTool(repoPath));
if (!tool) {
const viewDocs = 'View Git Docs';
const result = await window.showWarningMessage(
@ -173,7 +172,7 @@ export class ExternalDiffCommand extends Command {
}
for (const file of args.files) {
void Container.instance.git.openDiffTool(repoPath, file.uri, {
void this.container.git.openDiffTool(repoPath, file.uri, {
ref1: file.ref1,
ref2: file.ref2,
staged: file.staged,

+ 4
- 4
src/commands/git/branch.ts View File

@ -83,8 +83,8 @@ export interface BranchGitCommandArgs {
export class BranchGitCommand extends QuickCommand<State> {
private subcommand: State['subcommand'] | undefined;
constructor(args?: BranchGitCommandArgs) {
super('branch', 'branch', 'Branch', {
constructor(container: Container, args?: BranchGitCommandArgs) {
super(container, 'branch', 'branch', 'Branch', {
description: 'create, rename, or delete branches',
});
@ -150,8 +150,8 @@ export class BranchGitCommand extends QuickCommand {
protected async *steps(state: PartialStepState<State>): StepGenerator {
const context: Context = {
associatedView: Container.instance.branchesView,
repos: Container.instance.git.openRepositories,
associatedView: this.container.branchesView,
repos: this.container.git.openRepositories,
showTags: false,
title: this.title,
};

+ 5
- 5
src/commands/git/cherry-pick.ts View File

@ -44,8 +44,8 @@ export interface CherryPickGitCommandArgs {
type CherryPickStepState<T extends State = State> = ExcludeSome<StepState<T>, 'repo', string>;
export class CherryPickGitCommand extends QuickCommand<State> {
constructor(args?: CherryPickGitCommandArgs) {
super('cherry-pick', 'cherry-pick', 'Cherry Pick', {
constructor(container: Container, args?: CherryPickGitCommandArgs) {
super(container, 'cherry-pick', 'cherry-pick', 'Cherry Pick', {
description: 'integrates changes from specified commits into the current branch',
});
@ -82,8 +82,8 @@ export class CherryPickGitCommand extends QuickCommand {
protected async *steps(state: PartialStepState<State>): StepGenerator {
const context: Context = {
repos: Container.instance.git.openRepositories,
associatedView: Container.instance.commitsView,
repos: this.container.git.openRepositories,
associatedView: this.container.commitsView,
cache: new Map<string, Promise<GitLog | undefined>>(),
destination: undefined!,
selectedBranchOrTag: undefined,
@ -165,7 +165,7 @@ export class CherryPickGitCommand extends QuickCommand {
let log = context.cache.get(ref);
if (log == null) {
log = Container.instance.git.getLog(state.repo.path, { ref: ref, merges: false });
log = this.container.git.getLog(state.repo.path, { ref: ref, merges: false });
context.cache.set(ref, log);
}

+ 9
- 7
src/commands/git/coauthors.ts View File

@ -34,8 +34,10 @@ export interface CoAuthorsGitCommandArgs {
type CoAuthorStepState<T extends State = State> = ExcludeSome<StepState<T>, 'repo', string>;
export class CoAuthorsGitCommand extends QuickCommand<State> {
constructor(args?: CoAuthorsGitCommandArgs) {
super('co-authors', 'co-authors', 'Add Co-Authors', { description: 'adds co-authors to a commit message' });
constructor(container: Container, args?: CoAuthorsGitCommandArgs) {
super(container, 'co-authors', 'co-authors', 'Add Co-Authors', {
description: 'adds co-authors to a commit message',
});
let counter = 0;
if (args?.state?.repo != null) {
@ -61,7 +63,7 @@ export class CoAuthorsGitCommand extends QuickCommand {
}
async execute(state: CoAuthorStepState) {
const repo = await Container.instance.git.getOrOpenScmRepository(state.repo.path);
const repo = await this.container.git.getOrOpenScmRepository(state.repo.path);
if (repo == null) return;
let message = repo.inputBox.value;
@ -94,13 +96,13 @@ export class CoAuthorsGitCommand extends QuickCommand {
protected async *steps(state: PartialStepState<State>): StepGenerator {
const context: Context = {
repos: Container.instance.git.openRepositories,
repos: this.container.git.openRepositories,
activeRepo: undefined,
associatedView: Container.instance.contributorsView,
associatedView: this.container.contributorsView,
title: this.title,
};
const scmRepositories = await Container.instance.git.getOpenScmRepositories();
const scmRepositories = await this.container.git.getOpenScmRepositories();
if (scmRepositories.length) {
// Filter out any repo's that are not known to the built-in git
context.repos = context.repos.filter(repo =>
@ -108,7 +110,7 @@ export class CoAuthorsGitCommand extends QuickCommand {
);
// Ensure that the active repo is known to the built-in git
context.activeRepo = await Container.instance.git.getActiveRepository();
context.activeRepo = await this.container.git.getActiveRepository();
if (
context.activeRepo != null &&
!scmRepositories.some(r => r.rootUri.fsPath === context.activeRepo!.path)

+ 5
- 5
src/commands/git/fetch.ts View File

@ -41,8 +41,8 @@ export interface FetchGitCommandArgs {
type FetchStepState<T extends State = State> = ExcludeSome<StepState<T>, 'repos', string | string[] | Repository>;
export class FetchGitCommand extends QuickCommand<State> {
constructor(args?: FetchGitCommandArgs) {
super('fetch', 'fetch', 'Fetch', { description: 'fetches changes from one or more remotes' });
constructor(container: Container, args?: FetchGitCommandArgs) {
super(container, 'fetch', 'fetch', 'Fetch', { description: 'fetches changes from one or more remotes' });
let counter = 0;
if (args?.state?.repos != null && (!Array.isArray(args.state.repos) || args.state.repos.length !== 0)) {
@ -61,7 +61,7 @@ export class FetchGitCommand extends QuickCommand {
return state.repos[0].fetch({ branch: state.reference });
}
return Container.instance.git.fetchAll(state.repos, {
return this.container.git.fetchAll(state.repos, {
all: state.flags.includes('--all'),
prune: state.flags.includes('--prune'),
});
@ -69,8 +69,8 @@ export class FetchGitCommand extends QuickCommand {
protected async *steps(state: PartialStepState<State>): StepGenerator {
const context: Context = {
repos: Container.instance.git.openRepositories,
associatedView: Container.instance.commitsView,
repos: this.container.git.openRepositories,
associatedView: this.container.commitsView,
title: this.title,
};

+ 8
- 7
src/commands/git/log.ts View File

@ -40,8 +40,8 @@ export interface LogGitCommandArgs {
}
export class LogGitCommand extends QuickCommand<State> {
constructor(args?: LogGitCommandArgs) {
super('log', 'history', 'Commits', {
constructor(container: Container, args?: LogGitCommandArgs) {
super(container, 'log', 'history', 'Commits', {
description: 'aka log, shows commit history',
});
@ -78,8 +78,8 @@ export class LogGitCommand extends QuickCommand {
protected async *steps(state: PartialStepState<State>): StepGenerator {
const context: Context = {
repos: Container.instance.git.openRepositories,
associatedView: Container.instance.commitsView,
repos: this.container.git.openRepositories,
associatedView: this.container.commitsView,
cache: new Map<string, Promise<GitLog | undefined>>(),
selectedBranchOrTag: undefined,
title: this.title,
@ -155,8 +155,8 @@ export class LogGitCommand extends QuickCommand {
if (log == null) {
log =
state.fileName != null
? Container.instance.git.getLogForFile(state.repo.path, state.fileName, { ref: ref })
: Container.instance.git.getLog(state.repo.path, { ref: ref });
? this.container.git.getLogForFile(state.repo.path, state.fileName, { ref: ref })
: this.container.git.getLog(state.repo.path, { ref: ref });
context.cache.set(ref, log);
}
@ -178,10 +178,11 @@ export class LogGitCommand extends QuickCommand {
}
if (!(state.reference instanceof GitLogCommit) || state.reference.isFile) {
state.reference = await Container.instance.git.getCommit(state.repo.path, state.reference.ref);
state.reference = await this.container.git.getCommit(state.repo.path, state.reference.ref);
}
const result = yield* GitCommandsCommand.getSteps(
this.container,
{
command: 'show',
state: {

+ 6
- 6
src/commands/git/merge.ts View File

@ -48,8 +48,8 @@ export interface MergeGitCommandArgs {
type MergeStepState<T extends State = State> = ExcludeSome<StepState<T>, 'repo', string>;
export class MergeGitCommand extends QuickCommand<State> {
constructor(args?: MergeGitCommandArgs) {
super('merge', 'merge', 'Merge', {
constructor(container: Container, args?: MergeGitCommandArgs) {
super(container, 'merge', 'merge', 'Merge', {
description: 'integrates changes from a specified branch into the current branch',
});
@ -79,8 +79,8 @@ export class MergeGitCommand extends QuickCommand {
protected async *steps(state: PartialStepState<State>): StepGenerator {
const context: Context = {
repos: Container.instance.git.openRepositories,
associatedView: Container.instance.commitsView,
repos: this.container.git.openRepositories,
associatedView: this.container.commitsView,
cache: new Map<string, Promise<GitLog | undefined>>(),
destination: undefined!,
pickCommit: false,
@ -165,7 +165,7 @@ export class MergeGitCommand extends QuickCommand {
let log = context.cache.get(ref);
if (log == null) {
log = Container.instance.git.getLog(state.repo.path, { ref: ref, merges: false });
log = this.container.git.getLog(state.repo.path, { ref: ref, merges: false });
context.cache.set(ref, log);
}
@ -201,7 +201,7 @@ export class MergeGitCommand extends QuickCommand {
}
private async *confirmStep(state: MergeStepState, context: Context): AsyncStepResultGenerator<Flags[]> {
const aheadBehind = await Container.instance.git.getAheadBehindCommitCount(state.repo.path, [
const aheadBehind = await this.container.git.getAheadBehindCommitCount(state.repo.path, [
GitRevision.createRange(context.destination.name, state.reference.name),
]);
const count = aheadBehind != null ? aheadBehind.ahead + aheadBehind.behind : 0;

+ 5
- 5
src/commands/git/pull.ts View File

@ -42,8 +42,8 @@ export interface PullGitCommandArgs {
type PullStepState<T extends State = State> = ExcludeSome<StepState<T>, 'repos', string | string[] | Repository>;
export class PullGitCommand extends QuickCommand<State> {
constructor(args?: PullGitCommandArgs) {
super('pull', 'pull', 'Pull', {
constructor(container: Container, args?: PullGitCommandArgs) {
super(container, 'pull', 'pull', 'Pull', {
description: 'fetches and integrates changes from a remote into the current branch',
});
@ -70,13 +70,13 @@ export class PullGitCommand extends QuickCommand {
}
}
return Container.instance.git.pullAll(state.repos, { rebase: state.flags.includes('--rebase') });
return this.container.git.pullAll(state.repos, { rebase: state.flags.includes('--rebase') });
}
protected async *steps(state: PartialStepState<State>): StepGenerator {
const context: Context = {
repos: Container.instance.git.openRepositories,
associatedView: Container.instance.commitsView,
repos: this.container.git.openRepositories,
associatedView: this.container.commitsView,
title: this.title,
};

+ 6
- 6
src/commands/git/push.ts View File

@ -44,8 +44,8 @@ export interface PushGitCommandArgs {
type PushStepState<T extends State = State> = ExcludeSome<StepState<T>, 'repos', string | string[] | Repository>;
export class PushGitCommand extends QuickCommand<State> {
constructor(args?: PushGitCommandArgs) {
super('push', 'push', 'Push', {
constructor(container: Container, args?: PushGitCommandArgs) {
super(container, 'push', 'push', 'Push', {
description: 'pushes changes from the current branch to a remote',
});
@ -66,14 +66,14 @@ export class PushGitCommand extends QuickCommand {
if (index !== -1) {
if (!GitReference.isBranch(state.reference)) return Promise.resolve();
return Container.instance.git.pushAll(state.repos, {
return this.container.git.pushAll(state.repos, {
force: false,
publish: { remote: state.flags[index + 1] },
reference: state.reference,
});
}
return Container.instance.git.pushAll(state.repos, {
return this.container.git.pushAll(state.repos, {
force: state.flags.includes('--force'),
reference: state.reference,
});
@ -81,8 +81,8 @@ export class PushGitCommand extends QuickCommand {
protected async *steps(state: PartialStepState<State>): StepGenerator {
const context: Context = {
repos: Container.instance.git.openRepositories,
associatedView: Container.instance.commitsView,
repos: this.container.git.openRepositories,
associatedView: this.container.commitsView,
title: this.title,
};

+ 7
- 7
src/commands/git/rebase.ts View File

@ -49,8 +49,8 @@ export interface RebaseGitCommandArgs {
type RebaseStepState<T extends State = State> = ExcludeSome<StepState<T>, 'repo', string>;
export class RebaseGitCommand extends QuickCommand<State> {
constructor(args?: RebaseGitCommandArgs) {
super('rebase', 'rebase', 'Rebase', {
constructor(container: Container, args?: RebaseGitCommandArgs) {
super(container, 'rebase', 'rebase', 'Rebase', {
description:
'integrates changes from a specified branch into the current branch, by changing the base of the branch and reapplying the commits on top',
});
@ -78,7 +78,7 @@ export class RebaseGitCommand extends QuickCommand {
async execute(state: RebaseStepState) {
let configs: string[] | undefined;
if (state.flags.includes('--interactive')) {
await Container.instance.rebaseEditor.enableForNextUse();
await this.container.rebaseEditor.enableForNextUse();
let editor;
switch (env.appName) {
@ -103,8 +103,8 @@ export class RebaseGitCommand extends QuickCommand {
protected async *steps(state: PartialStepState<State>): StepGenerator {
const context: Context = {
repos: Container.instance.git.openRepositories,
associatedView: Container.instance.commitsView,
repos: this.container.git.openRepositories,
associatedView: this.container.commitsView,
cache: new Map<string, Promise<GitLog | undefined>>(),
destination: undefined!,
pickCommit: false,
@ -189,7 +189,7 @@ export class RebaseGitCommand extends QuickCommand {
let log = context.cache.get(ref);
if (log == null) {
log = Container.instance.git.getLog(state.repo.path, { ref: ref, merges: false });
log = this.container.git.getLog(state.repo.path, { ref: ref, merges: false });
context.cache.set(ref, log);
}
@ -225,7 +225,7 @@ export class RebaseGitCommand extends QuickCommand {
}
private async *confirmStep(state: RebaseStepState, context: Context): AsyncStepResultGenerator<Flags[]> {
const aheadBehind = await Container.instance.git.getAheadBehindCommitCount(state.repo.path, [
const aheadBehind = await this.container.git.getAheadBehindCommitCount(state.repo.path, [
state.reference.refType === 'revision'
? GitRevision.createRange(state.reference.ref, context.destination.ref)
: GitRevision.createRange(context.destination.name, state.reference.name),

+ 5
- 5
src/commands/git/reset.ts View File

@ -42,8 +42,8 @@ export interface ResetGitCommandArgs {
type ResetStepState<T extends State = State> = ExcludeSome<StepState<T>, 'repo', string>;
export class ResetGitCommand extends QuickCommand<State> {
constructor(args?: ResetGitCommandArgs) {
super('reset', 'reset', 'Reset', { description: 'resets the current branch to a specified commit' });
constructor(container: Container, args?: ResetGitCommandArgs) {
super(container, 'reset', 'reset', 'Reset', { description: 'resets the current branch to a specified commit' });
let counter = 0;
if (args?.state?.repo != null) {
@ -73,8 +73,8 @@ export class ResetGitCommand extends QuickCommand {
protected async *steps(state: PartialStepState<State>): StepGenerator {
const context: Context = {
repos: Container.instance.git.openRepositories,
associatedView: Container.instance.commitsView,
repos: this.container.git.openRepositories,
associatedView: this.container.commitsView,
cache: new Map<string, Promise<GitLog | undefined>>(),
destination: undefined!,
title: this.title,
@ -121,7 +121,7 @@ export class ResetGitCommand extends QuickCommand {
let log = context.cache.get(ref);
if (log == null) {
log = Container.instance.git.getLog(state.repo.path, { ref: ref, merges: false });
log = this.container.git.getLog(state.repo.path, { ref: ref, merges: false });
context.cache.set(ref, log);
}

+ 5
- 5
src/commands/git/revert.ts View File

@ -41,8 +41,8 @@ export interface RevertGitCommandArgs {
type RevertStepState<T extends State = State> = ExcludeSome<StepState<T>, 'repo', string>;
export class RevertGitCommand extends QuickCommand<State> {
constructor(args?: RevertGitCommandArgs) {
super('revert', 'revert', 'Revert', {
constructor(container: Container, args?: RevertGitCommandArgs) {
super(container, 'revert', 'revert', 'Revert', {
description: 'undoes the changes of specified commits, by creating new commits with inverted changes',
});
@ -75,8 +75,8 @@ export class RevertGitCommand extends QuickCommand {
protected async *steps(state: PartialStepState<State>): StepGenerator {
const context: Context = {
repos: Container.instance.git.openRepositories,
associatedView: Container.instance.commitsView,
repos: this.container.git.openRepositories,
associatedView: this.container.commitsView,
cache: new Map<string, Promise<GitLog | undefined>>(),
destination: undefined!,
title: this.title,
@ -125,7 +125,7 @@ export class RevertGitCommand extends QuickCommand {
let log = context.cache.get(ref);
if (log == null) {
log = Container.instance.git.getLog(state.repo.path, { ref: ref, merges: false });
log = this.container.git.getLog(state.repo.path, { ref: ref, merges: false });
context.cache.set(ref, log);
}

+ 9
- 8
src/commands/git/search.ts View File

@ -59,8 +59,8 @@ const searchOperatorToTitleMap = new Map([
type SearchStepState<T extends State = State> = ExcludeSome<StepState<T>, 'repo', string>;
export class SearchGitCommand extends QuickCommand<State> {
constructor(args?: SearchGitCommandArgs) {
super('search', 'search', 'Commit Search', {
constructor(container: Container, args?: SearchGitCommandArgs) {
super(container, 'search', 'search', 'Commit Search', {
description: 'aka grep, searches for commits',
});
@ -94,15 +94,15 @@ export class SearchGitCommand extends QuickCommand {
protected async *steps(state: PartialStepState<State>): StepGenerator {
const context: Context = {
repos: Container.instance.git.openRepositories,
associatedView: Container.instance.searchAndCompareView,
repos: this.container.git.openRepositories,
associatedView: this.container.searchAndCompareView,
commit: undefined,
resultsKey: undefined,
resultsPromise: undefined,
title: this.title,
};
const cfg = Container.instance.config.gitCommands.search;
const cfg = this.container.config.gitCommands.search;
if (state.matchAll == null) {
state.matchAll = cfg.matchAll;
}
@ -170,7 +170,7 @@ export class SearchGitCommand extends QuickCommand {
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
if (state.showResultsInSideBar) {
void Container.instance.searchAndCompareView.search(
void this.container.searchAndCompareView.search(
state.repo.path,
search,
{
@ -199,7 +199,7 @@ export class SearchGitCommand extends QuickCommand {
showInSideBarCommand: new ActionQuickPickItem(
'$(link-external) Show Results in Side Bar',
() =>
void Container.instance.searchAndCompareView.search(
void this.container.searchAndCompareView.search(
repoPath,
search,
{
@ -216,7 +216,7 @@ export class SearchGitCommand extends QuickCommand {
showInSideBarButton: {
button: QuickCommandButtons.ShowResultsInSideBar,
onDidClick: () =>
void Container.instance.searchAndCompareView.search(
void this.container.searchAndCompareView.search(
repoPath,
search,
{
@ -240,6 +240,7 @@ export class SearchGitCommand extends QuickCommand {
}
const result = yield* GitCommandsCommand.getSteps(
this.container,
{
command: 'show',
state: {

+ 5
- 8
src/commands/git/show.ts View File

@ -36,8 +36,8 @@ export interface ShowGitCommandArgs {
type ShowStepState<T extends State = State> = ExcludeSome<StepState<T>, 'repo', string>;
export class ShowGitCommand extends QuickCommand<State> {
constructor(args?: ShowGitCommandArgs) {
super('show', 'show', 'Show', {
constructor(container: Container, args?: ShowGitCommandArgs) {
super(container, 'show', 'show', 'Show', {
description: 'shows information about a git reference',
});
@ -78,8 +78,8 @@ export class ShowGitCommand extends QuickCommand {
protected async *steps(state: PartialStepState<State>): StepGenerator {
const context: Context = {
repos: Container.instance.git.openRepositories,
associatedView: Container.instance.commitsView,
repos: this.container.git.openRepositories,
associatedView: this.container.commitsView,
title: this.title,
};
@ -113,10 +113,7 @@ export class ShowGitCommand extends QuickCommand {
state.reference.isFile
) {
if (state.reference != null && (!GitLogCommit.is(state.reference) || state.reference.isFile)) {
state.reference = await Container.instance.git.getCommit(
state.reference.repoPath,
state.reference.ref,
);
state.reference = await this.container.git.getCommit(state.reference.repoPath, state.reference.ref);
}
if (state.counter < 2 || state.reference == null) {

+ 9
- 8
src/commands/git/stash.ts View File

@ -95,8 +95,8 @@ export interface StashGitCommandArgs {
export class StashGitCommand extends QuickCommand<State> {
private subcommand: State['subcommand'] | undefined;
constructor(args?: StashGitCommandArgs) {
super('stash', 'stash', 'Stash', {
constructor(container: Container, args?: StashGitCommandArgs) {
super(container, 'stash', 'stash', 'Stash', {
description: 'shelves (stashes) local changes to be reapplied later',
});
@ -147,8 +147,8 @@ export class StashGitCommand extends QuickCommand {
protected async *steps(state: PartialStepState<State>): StepGenerator {
const context: Context = {
repos: Container.instance.git.openRepositories,
associatedView: Container.instance.stashesView,
repos: this.container.git.openRepositories,
associatedView: this.container.stashesView,
title: this.title,
};
@ -262,7 +262,7 @@ export class StashGitCommand extends QuickCommand {
while (this.canStepsContinue(state)) {
if (state.counter < 3 || state.reference == null) {
const result: StepResult<GitStashReference> = yield* pickStashStep(state, context, {
stash: await Container.instance.git.getStash(state.repo.path),
stash: await this.container.git.getStash(state.repo.path),
placeholder: (context, stash) =>
stash == null
? `No stashes found in ${state.repo.formattedName}`
@ -360,7 +360,7 @@ export class StashGitCommand extends QuickCommand {
while (this.canStepsContinue(state)) {
if (state.counter < 3 || state.reference == null) {
const result: StepResult<GitStashReference> = yield* pickStashStep(state, context, {
stash: await Container.instance.git.getStash(state.repo.path),
stash: await this.container.git.getStash(state.repo.path),
placeholder: (context, stash) =>
stash == null ? `No stashes found in ${state.repo.formattedName}` : 'Choose a stash to delete',
picked: state.reference?.ref,
@ -421,7 +421,7 @@ export class StashGitCommand extends QuickCommand {
while (this.canStepsContinue(state)) {
if (state.counter < 3 || state.reference == null) {
const result: StepResult<GitStashCommit> = yield* pickStashStep(state, context, {
stash: await Container.instance.git.getStash(state.repo.path),
stash: await this.container.git.getStash(state.repo.path),
placeholder: (context, stash) =>
stash == null ? `No stashes found in ${state.repo.formattedName}` : 'Choose a stash',
picked: state.reference?.ref,
@ -433,10 +433,11 @@ export class StashGitCommand extends QuickCommand {
}
// if (!(state.reference instanceof GitStashCommit)) {
// state.reference = await Container.instance.git.getCommit(state.repo.path, state.reference.ref);
// state.reference = await this.container.git.getCommit(state.repo.path, state.reference.ref);
// }
const result = yield* GitCommandsCommand.getSteps(
this.container,
{
command: 'show',
state: {

+ 4
- 4
src/commands/git/status.ts View File

@ -34,8 +34,8 @@ export interface StatusGitCommandArgs {
type StatusStepState<T extends State = State> = ExcludeSome<StepState<T>, 'repo', string>;
export class StatusGitCommand extends QuickCommand<State> {
constructor(args?: StatusGitCommandArgs) {
super('status', 'status', 'Status', {
constructor(container: Container, args?: StatusGitCommandArgs) {
super(container, 'status', 'status', 'Status', {
description: 'shows status information about a repository',
});
@ -57,8 +57,8 @@ export class StatusGitCommand extends QuickCommand {
protected async *steps(state: PartialStepState<State>): StepGenerator {
const context: Context = {
repos: Container.instance.git.openRepositories,
associatedView: Container.instance.commitsView,
repos: this.container.git.openRepositories,
associatedView: this.container.commitsView,
status: undefined!,
title: this.title,
};

+ 5
- 5
src/commands/git/switch.ts View File

@ -42,8 +42,8 @@ export interface SwitchGitCommandArgs {
}
export class SwitchGitCommand extends QuickCommand<State> {
constructor(args?: SwitchGitCommandArgs) {
super('switch', 'switch', 'Switch', {
constructor(container: Container, args?: SwitchGitCommandArgs) {
super(container, 'switch', 'switch', 'Switch', {
description: 'aka checkout, switches the current branch to a specified branch',
});
@ -90,8 +90,8 @@ export class SwitchGitCommand extends QuickCommand {
protected async *steps(state: PartialStepState<State>): StepGenerator {
const context: Context = {
repos: Container.instance.git.openRepositories,
associatedView: Container.instance.commitsView,
repos: this.container.git.openRepositories,
associatedView: this.container.commitsView,
showTags: false,
title: this.title,
};
@ -149,7 +149,7 @@ export class SwitchGitCommand extends QuickCommand {
if (GitReference.isBranch(state.reference) && state.reference.remote) {
context.title = `Create Branch and ${this.title}`;
const { values: branches } = await Container.instance.git.getBranches(state.reference.repoPath, {
const { values: branches } = await this.container.git.getBranches(state.reference.repoPath, {
filter: b => b.upstream?.name === state.reference!.name,
sort: { orderBy: BranchSorting.DateDesc },
});

+ 4
- 4
src/commands/git/tag.ts View File

@ -68,8 +68,8 @@ export interface TagGitCommandArgs {
export class TagGitCommand extends QuickCommand<State> {
private subcommand: State['subcommand'] | undefined;
constructor(args?: TagGitCommandArgs) {
super('tag', 'tag', 'Tag', {
constructor(container: Container, args?: TagGitCommandArgs) {
super(container, 'tag', 'tag', 'Tag', {
description: 'create, or delete tags',
});
@ -129,8 +129,8 @@ export class TagGitCommand extends QuickCommand {
protected async *steps(state: PartialStepState<State>): StepGenerator {
const context: Context = {
repos: Container.instance.git.openRepositories,
associatedView: Container.instance.tagsView,
repos: this.container.git.openRepositories,
associatedView: this.container.tagsView,
showTags: false,
title: this.title,
};

+ 32
- 29
src/commands/gitCommands.ts View File

@ -2,7 +2,7 @@
import { Disposable, InputBox, QuickInputButton, QuickInputButtons, QuickPick, QuickPickItem, window } from 'vscode';
import { configuration, GitCommandSorting } from '../configuration';
import { Usage, WorkspaceState } from '../constants';
import { Container } from '../container';
import type { Container } from '../container';
import { KeyMapping } from '../keyboard';
import { Directive, DirectiveQuickPickItem } from '../quickpicks';
import { log, Promises } from '../system';
@ -65,8 +65,8 @@ function* nullSteps(): StepGenerator {
@command()
export class GitCommandsCommand extends Command {
static getSteps(args: GitCommandsCommandArgs, pickedVia: 'menu' | 'command'): StepGenerator {
const commandsStep = new PickCommandStep(args);
static getSteps(container: Container, args: GitCommandsCommandArgs, pickedVia: 'menu' | 'command'): StepGenerator {
const commandsStep = new PickCommandStep(container, args);
const command = commandsStep.find(args.command);
if (command == null) return nullSteps();
@ -78,7 +78,7 @@ export class GitCommandsCommand extends Command {
private startedWith: 'menu' | 'command' = 'menu';
constructor() {
constructor(private readonly container: Container) {
super([
Commands.GitCommands,
Commands.GitCommandsBranch,
@ -125,7 +125,7 @@ export class GitCommandsCommand extends Command {
@log({ args: false, correlate: true, singleLine: true, timed: false })
async execute(args?: GitCommandsCommandArgs) {
const commandsStep = new PickCommandStep(args);
const commandsStep = new PickCommandStep(this.container, args);
const command = args?.command != null ? commandsStep.find(args.command) : undefined;
this.startedWith = command != null ? 'command' : 'menu';
@ -310,7 +310,7 @@ export class GitCommandsCommand extends Command {
}
}
const scope = Container.instance.keyboard.createScope(mapping);
const scope = this.container.keyboard.createScope(mapping);
void scope.start();
disposables.push(
@ -459,7 +459,7 @@ export class GitCommandsCommand extends Command {
}
}
const scope = Container.instance.keyboard.createScope(mapping);
const scope = this.container.keyboard.createScope(mapping);
void scope.start();
let overrideItems = false;
@ -747,29 +747,32 @@ class PickCommandStep implements QuickPickStep {
readonly placeholder = 'Choose a git command';
readonly title = 'GitLens';
constructor(args?: GitCommandsCommandArgs) {
constructor(private readonly container: Container, args?: GitCommandsCommandArgs) {
this.items = [
new BranchGitCommand(args?.command === 'branch' ? args : undefined),
new CherryPickGitCommand(args?.command === 'cherry-pick' ? args : undefined),
new CoAuthorsGitCommand(args?.command === 'co-authors' ? args : undefined),
new FetchGitCommand(args?.command === 'fetch' ? args : undefined),
new LogGitCommand(args?.command === 'log' ? args : undefined),
new MergeGitCommand(args?.command === 'merge' ? args : undefined),
new PullGitCommand(args?.command === 'pull' ? args : undefined),
new PushGitCommand(args?.command === 'push' ? args : undefined),
new RebaseGitCommand(args?.command === 'rebase' ? args : undefined),
new ResetGitCommand(args?.command === 'reset' ? args : undefined),
new RevertGitCommand(args?.command === 'revert' ? args : undefined),
new SearchGitCommand(args?.command === 'search' || args?.command === 'grep' ? args : undefined),
new ShowGitCommand(args?.command === 'show' ? args : undefined),
new StashGitCommand(args?.command === 'stash' ? args : undefined),
new StatusGitCommand(args?.command === 'status' ? args : undefined),
new SwitchGitCommand(args?.command === 'switch' || args?.command === 'checkout' ? args : undefined),
new TagGitCommand(args?.command === 'tag' ? args : undefined),
new BranchGitCommand(container, args?.command === 'branch' ? args : undefined),
new CherryPickGitCommand(container, args?.command === 'cherry-pick' ? args : undefined),
new CoAuthorsGitCommand(container, args?.command === 'co-authors' ? args : undefined),
new FetchGitCommand(container, args?.command === 'fetch' ? args : undefined),
new LogGitCommand(container, args?.command === 'log' ? args : undefined),
new MergeGitCommand(container, args?.command === 'merge' ? args : undefined),
new PullGitCommand(container, args?.command === 'pull' ? args : undefined),
new PushGitCommand(container, args?.command === 'push' ? args : undefined),
new RebaseGitCommand(container, args?.command === 'rebase' ? args : undefined),
new ResetGitCommand(container, args?.command === 'reset' ? args : undefined),
new RevertGitCommand(container, args?.command === 'revert' ? args : undefined),
new SearchGitCommand(container, args?.command === 'search' || args?.command === 'grep' ? args : undefined),
new ShowGitCommand(container, args?.command === 'show' ? args : undefined),
new StashGitCommand(container, args?.command === 'stash' ? args : undefined),
new StatusGitCommand(container, args?.command === 'status' ? args : undefined),
new SwitchGitCommand(
container,
args?.command === 'switch' || args?.command === 'checkout' ? args : undefined,
),
new TagGitCommand(container, args?.command === 'tag' ? args : undefined),
];
if (Container.instance.config.gitCommands.sortBy === GitCommandSorting.Usage) {
const usage = Container.instance.context.workspaceState.get<Usage>(WorkspaceState.GitCommandPaletteUsage);
if (this.container.config.gitCommands.sortBy === GitCommandSorting.Usage) {
const usage = this.container.context.workspaceState.get<Usage>(WorkspaceState.GitCommandPaletteUsage);
if (usage != null) {
this.items.sort((a, b) => (usage[b.key] ?? 0) - (usage[a.key] ?? 0));
}
@ -809,12 +812,12 @@ class PickCommandStep implements QuickPickStep {
}
private async updateCommandUsage(id: string, timestamp: number) {
let usage = Container.instance.context.workspaceState.get<Usage>(WorkspaceState.GitCommandPaletteUsage);
let usage = this.container.context.workspaceState.get<Usage>(WorkspaceState.GitCommandPaletteUsage);
if (usage === undefined) {
usage = Object.create(null) as Usage;
}
usage[id] = timestamp;
await Container.instance.context.workspaceState.update(WorkspaceState.GitCommandPaletteUsage, usage);
await this.container.context.workspaceState.update(WorkspaceState.GitCommandPaletteUsage, usage);
}
}

+ 4
- 4
src/commands/inviteToLiveShare.ts View File

@ -1,5 +1,5 @@
'use strict';
import { Container } from '../container';
import type { Container } from '../container';
import { command, Command, CommandContext, Commands, isCommandContextViewNodeHasContributor } from './common';
export interface InviteToLiveShareCommandArgs {
@ -16,7 +16,7 @@ export class InviteToLiveShareCommand extends Command {
return super.getMarkdownCommandArgsCore<InviteToLiveShareCommandArgs>(Commands.InviteToLiveShare, args);
}
constructor() {
constructor(private readonly container: Container) {
super(Commands.InviteToLiveShare);
}
@ -32,12 +32,12 @@ export class InviteToLiveShareCommand extends Command {
async execute(args?: InviteToLiveShareCommandArgs) {
if (args?.email) {
const contact = await Container.instance.vsls.getContact(args.email);
const contact = await this.container.vsls.getContact(args.email);
if (contact != null) {
return contact.invite();
}
}
return Container.instance.vsls.startSession();
return this.container.vsls.startSession();
}
}

+ 3
- 2
src/commands/logging.ts View File

@ -1,10 +1,11 @@
'use strict';
import { configuration, OutputLevel } from '../configuration';
import type { Container } from '../container';
import { command, Command, Commands } from './common';
@command()
export class EnableDebugLoggingCommand extends Command {
constructor() {
constructor(private readonly container: Container) {
super(Commands.EnableDebugLogging);
}
@ -15,7 +16,7 @@ export class EnableDebugLoggingCommand extends Command {
@command()
export class DisableDebugLoggingCommand extends Command {
constructor() {
constructor(private readonly container: Container) {
super(Commands.DisableDebugLogging);
}

+ 3
- 3
src/commands/openAssociatedPullRequestOnRemote.ts View File

@ -1,6 +1,6 @@
'use strict';
import { TextEditor, Uri } from 'vscode';
import { Container } from '../container';
import type { Container } from '../container';
import { GitUri } from '../git/gitUri';
import { Logger } from '../logger';
import { ActiveEditorCommand, command, Commands, executeCommand, getCommandUri } from './common';
@ -8,7 +8,7 @@ import { OpenPullRequestOnRemoteCommandArgs } from './openPullRequestOnRemote';
@command()
export class OpenAssociatedPullRequestOnRemoteCommand extends ActiveEditorCommand {
constructor() {
constructor(private readonly container: Container) {
super(Commands.OpenAssociatedPullRequestOnRemote);
}
@ -24,7 +24,7 @@ export class OpenAssociatedPullRequestOnRemoteCommand extends ActiveEditorComman
if (blameline < 0) return;
try {
const blame = await Container.instance.git.getBlameForLine(gitUri, blameline);
const blame = await this.container.git.getBlameForLine(gitUri, blameline);
if (blame == null) return;
await executeCommand<OpenPullRequestOnRemoteCommandArgs>(Commands.OpenPullRequestOnRemote, {

+ 2
- 1
src/commands/openBranchOnRemote.ts View File

@ -1,5 +1,6 @@
'use strict';
import { TextEditor, Uri, window } from 'vscode';
import type { Container } from '../container';
import { GitUri } from '../git/gitUri';
import { RemoteResourceType } from '../git/remotes/provider';
import { Logger } from '../logger';
@ -24,7 +25,7 @@ export interface OpenBranchOnRemoteCommandArgs {
@command()
export class OpenBranchOnRemoteCommand extends ActiveEditorCommand {
constructor() {
constructor(private readonly container: Container) {
super([Commands.OpenBranchOnRemote, Commands.Deprecated_OpenBranchInRemote, Commands.CopyRemoteBranchUrl]);
}

+ 2
- 1
src/commands/openBranchesOnRemote.ts View File

@ -1,5 +1,6 @@
'use strict';
import { TextEditor, Uri, window } from 'vscode';
import type { Container } from '../container';
import { GitUri } from '../git/gitUri';
import { RemoteResourceType } from '../git/remotes/provider';
import { Logger } from '../logger';
@ -22,7 +23,7 @@ export interface OpenBranchesOnRemoteCommandArgs {
@command()
export class OpenBranchesOnRemoteCommand extends ActiveEditorCommand {
constructor() {
constructor(private readonly container: Container) {
super([
Commands.OpenBranchesOnRemote,
Commands.Deprecated_OpenBranchesInRemote,

+ 3
- 3
src/commands/openChangedFiles.ts View File

@ -1,6 +1,6 @@
'use strict';
import { Uri, window } from 'vscode';
import { Container } from '../container';
import type { Container } from '../container';
import { Logger } from '../logger';
import { Messages } from '../messages';
import { Arrays } from '../system';
@ -12,7 +12,7 @@ export interface OpenChangedFilesCommandArgs {
@command()
export class OpenChangedFilesCommand extends Command {
constructor() {
constructor(private readonly container: Container) {
super(Commands.OpenChangedFiles);
}
@ -24,7 +24,7 @@ export class OpenChangedFilesCommand extends Command {
const repoPath = await getRepoPathOrPrompt('Open All Changed Files');
if (!repoPath) return;
const status = await Container.instance.git.getStatusForRepo(repoPath);
const status = await this.container.git.getStatusForRepo(repoPath);
if (status == null) {
void window.showWarningMessage('Unable to open changed files');

+ 4
- 4
src/commands/openCommitOnRemote.ts View File

@ -1,6 +1,6 @@
'use strict';
import { TextEditor, Uri, window } from 'vscode';
import { Container } from '../container';
import type { Container } from '../container';
import { GitUri } from '../git/gitUri';
import { RemoteResourceType } from '../git/remotes/provider';
import { Logger } from '../logger';
@ -31,7 +31,7 @@ export class OpenCommitOnRemoteCommand extends ActiveEditorCommand {
return super.getMarkdownCommandArgsCore<OpenCommitOnRemoteCommandArgs>(Commands.OpenCommitOnRemote, args);
}
constructor() {
constructor(private readonly container: Container) {
super([Commands.OpenCommitOnRemote, Commands.Deprecated_OpenCommitInRemote, Commands.CopyRemoteCommitUrl]);
}
@ -72,8 +72,8 @@ export class OpenCommitOnRemoteCommand extends ActiveEditorCommand {
if (blameline < 0) return;
const blame = editor?.document.isDirty
? await Container.instance.git.getBlameForLineContents(gitUri, blameline, editor.document.getText())
: await Container.instance.git.getBlameForLine(gitUri, blameline);
? await this.container.git.getBlameForLineContents(gitUri, blameline, editor.document.getText())
: await this.container.git.getBlameForLine(gitUri, blameline);
if (blame == null) {
void Messages.showFileNotUnderSourceControlWarningMessage(
'Unable to open commit on remote provider',

+ 2
- 1
src/commands/openComparisonOnRemote.ts View File

@ -1,5 +1,6 @@
'use strict';
import { window } from 'vscode';
import type { Container } from '../container';
import { RemoteResourceType } from '../git/remotes/provider';
import { Logger } from '../logger';
import { ResultsCommitsNode } from '../views/nodes';
@ -16,7 +17,7 @@ export interface OpenComparisonOnRemoteCommandArgs {
@command()
export class OpenComparisonOnRemoteCommand extends Command {
constructor() {
constructor(private readonly container: Container) {
super([Commands.OpenComparisonOnRemote, Commands.CopyRemoteComparisonUrl]);
}

+ 2
- 1
src/commands/openDirectoryCompare.ts View File

@ -1,6 +1,7 @@
'use strict';
import { TextEditor, Uri } from 'vscode';
import { GitActions } from '../commands';
import type { Container } from '../container';
import { Logger } from '../logger';
import { Messages } from '../messages';
import { ReferencePicker } from '../quickpicks';
@ -22,7 +23,7 @@ export interface OpenDirectoryCompareCommandArgs {
@command()
export class OpenDirectoryCompareCommand extends ActiveEditorCommand {
constructor() {
constructor(private readonly container: Container) {
super([
Commands.DiffDirectory,
Commands.DiffDirectoryWithHead,

+ 5
- 5
src/commands/openFileAtRevision.ts View File

@ -2,7 +2,7 @@
import { TextDocumentShowOptions, TextEditor, Uri } from 'vscode';
import { FileAnnotationType } from '../configuration';
import { GlyphChars, quickPickTitleMaxChars } from '../constants';
import { Container } from '../container';
import type { Container } from '../container';
import { GitUri } from '../git/gitUri';
import { GitRevision } from '../git/models';
import { Logger } from '../logger';
@ -46,7 +46,7 @@ export class OpenFileAtRevisionCommand extends ActiveEditorCommand {
return super.getMarkdownCommandArgsCore<OpenFileAtRevisionCommandArgs>(Commands.OpenFileAtRevision, args);
}
constructor() {
constructor(private readonly container: Container) {
super([Commands.OpenFileAtRevision, Commands.OpenBlamePriorToChange]);
}
@ -58,7 +58,7 @@ export class OpenFileAtRevisionCommand extends ActiveEditorCommand {
if (editorLine >= 0) {
try {
const gitUri = await GitUri.fromUri(context.editor.document.uri);
const blame = await Container.instance.git.getBlameForLine(gitUri, editorLine);
const blame = await this.container.git.getBlameForLine(gitUri, editorLine);
if (blame != null) {
if (blame.commit.isUncommitted) {
const diffUris = await blame.commit.getPreviousLineDiffUris(
@ -107,11 +107,11 @@ export class OpenFileAtRevisionCommand extends ActiveEditorCommand {
try {
if (args.revisionUri == null) {
const log = Container.instance.git.getLogForFile(gitUri.repoPath, gitUri.fsPath).then(
const log = this.container.git.getLogForFile(gitUri.repoPath, gitUri.fsPath).then(
log =>
log ??
(gitUri.sha
? Container.instance.git.getLogForFile(gitUri.repoPath, gitUri.fsPath, {
? this.container.git.getLogForFile(gitUri.repoPath, gitUri.fsPath, {
ref: gitUri.sha,
})
: undefined),

+ 3
- 3
src/commands/openFileAtRevisionFrom.ts View File

@ -2,7 +2,7 @@
import { TextDocumentShowOptions, TextEditor, Uri } from 'vscode';
import { FileAnnotationType } from '../configuration';
import { GlyphChars, quickPickTitleMaxChars } from '../constants';
import { Container } from '../container';
import type { Container } from '../container';
import { GitUri } from '../git/gitUri';
import { GitReference } from '../git/models';
import { Messages } from '../messages';
@ -23,7 +23,7 @@ export interface OpenFileAtRevisionFromCommandArgs {
@command()
export class OpenFileAtRevisionFromCommand extends ActiveEditorCommand {
constructor() {
constructor(private readonly container: Container) {
super(Commands.OpenFileAtRevisionFrom);
}
@ -48,7 +48,7 @@ export class OpenFileAtRevisionFromCommand extends ActiveEditorCommand {
const title = `Open Changes with Stash${Strings.pad(GlyphChars.Dot, 2, 2)}`;
const pick = await StashPicker.show(
Container.instance.git.getStash(gitUri.repoPath),
this.container.git.getStash(gitUri.repoPath),
`${title}${gitUri.getFormattedFileName({ truncateTo: quickPickTitleMaxChars - title.length })}`,
'Choose a stash to compare with',
{ filter: c => c.files.some(f => f.fileName === fileName || f.originalFileName === fileName) },

+ 4
- 4
src/commands/openFileFromRemote.ts View File

@ -1,11 +1,11 @@
'use strict';
import { env, Range, Uri, window } from 'vscode';
import { Container } from '../container';
import type { Container } from '../container';
import { command, Command, Commands, openEditor } from './common';
@command()
export class OpenFileFromRemoteCommand extends Command {
constructor() {
constructor(private readonly container: Container) {
super(Commands.OpenFileFromRemote);
}
@ -25,9 +25,9 @@ export class OpenFileFromRemoteCommand extends Command {
});
if (url == null || url.length === 0) return;
let local = await Container.instance.git.getLocalInfoFromRemoteUri(Uri.parse(url));
let local = await this.container.git.getLocalInfoFromRemoteUri(Uri.parse(url));
if (local == null) {
local = await Container.instance.git.getLocalInfoFromRemoteUri(Uri.parse(url), { validate: false });
local = await this.container.git.getLocalInfoFromRemoteUri(Uri.parse(url), { validate: false });
if (local == null) {
void window.showWarningMessage('Unable to parse the provided remote url.');

+ 5
- 5
src/commands/openFileOnRemote.ts View File

@ -3,7 +3,7 @@ import { Range, TextEditor, Uri, window } from 'vscode';
import { UriComparer } from '../comparers';
import { BranchSorting, TagSorting } from '../configuration';
import { GlyphChars } from '../constants';
import { Container } from '../container';
import type { Container } from '../container';
import { GitUri } from '../git/gitUri';
import { GitBranch, GitRevision } from '../git/models';
import { RemoteResourceType } from '../git/remotes/provider';
@ -33,7 +33,7 @@ export interface OpenFileOnRemoteCommandArgs {
@command()
export class OpenFileOnRemoteCommand extends ActiveEditorCommand {
constructor() {
constructor(private readonly container: Container) {
super([
Commands.OpenFileOnRemote,
Commands.Deprecated_OpenFileInRemote,
@ -84,7 +84,7 @@ export class OpenFileOnRemoteCommand extends ActiveEditorCommand {
const gitUri = await GitUri.fromUri(uri);
if (gitUri.repoPath) {
if (gitUri.sha == null) {
const commit = await Container.instance.git.getCommitForFile(gitUri.repoPath, gitUri, {
const commit = await this.container.git.getCommitForFile(gitUri.repoPath, gitUri, {
firstIfNotFound: true,
});
@ -116,7 +116,7 @@ export class OpenFileOnRemoteCommand extends ActiveEditorCommand {
args = { range: true, ...args };
try {
let remotes = await Container.instance.git.getRemotes(gitUri.repoPath);
let remotes = await this.container.git.getRemotes(gitUri.repoPath);
const range =
args.range && editor != null && UriComparer.equals(editor.document.uri, uri)
? new Range(
@ -144,7 +144,7 @@ export class OpenFileOnRemoteCommand extends ActiveEditorCommand {
if ((args.sha == null && args.branchOrTag == null) || args.pickBranchOrTag) {
let branch;
if (!args.pickBranchOrTag) {
branch = await Container.instance.git.getBranch(gitUri.repoPath);
branch = await this.container.git.getBranch(gitUri.repoPath);
}
if (branch?.upstream == null) {

+ 2
- 1
src/commands/openIssueOnRemote.ts View File

@ -1,5 +1,6 @@
'use strict';
import { env, Uri } from 'vscode';
import type { Container } from '../container';
import { AutolinkedItemNode } from '../views/nodes/autolinkedItemNode';
import { Command, command, CommandContext, Commands } from './common';
@ -10,7 +11,7 @@ export interface OpenIssueOnRemoteCommandArgs {
@command()
export class OpenIssueOnRemoteCommand extends Command {
constructor() {
constructor(private readonly container: Container) {
super([Commands.OpenIssueOnRemote, Commands.CopyRemoteIssueUrl]);
}

+ 4
- 4
src/commands/openOnRemote.ts View File

@ -1,6 +1,6 @@
'use strict';
import { GlyphChars } from '../constants';
import { Container } from '../container';
import type { Container } from '../container';
import { GitRemote, GitRevision } from '../git/models';
import { RemoteProvider, RemoteResource, RemoteResourceType } from '../git/remotes/provider';
import { Logger } from '../logger';
@ -27,14 +27,14 @@ export type OpenOnRemoteCommandArgs =
@command()
export class OpenOnRemoteCommand extends Command {
constructor() {
constructor(private readonly container: Container) {
super([Commands.OpenOnRemote, Commands.Deprecated_OpenInRemote]);
}
async execute(args?: OpenOnRemoteCommandArgs) {
if (args?.resource == null) return;
let remotes = 'remotes' in args ? args.remotes : await Container.instance.git.getRemotes(args.repoPath);
let remotes = 'remotes' in args ? args.remotes : await this.container.git.getRemotes(args.repoPath);
if (args.remote != null) {
const filtered = remotes.filter(r => r.name === args.remote);
@ -61,7 +61,7 @@ export class OpenOnRemoteCommand extends Command {
const file = commit?.files.find(f => f.fileName === fileName);
if (file?.status === 'D') {
// Resolve to the previous commit to that file
args.resource.sha = await Container.instance.git.resolveReference(
args.resource.sha = await this.container.git.resolveReference(
commit.repoPath,
`${commit.sha}^`,
fileName,

+ 4
- 4
src/commands/openPullRequestOnRemote.ts View File

@ -1,6 +1,6 @@
'use strict';
import { env, Uri } from 'vscode';
import { Container } from '../container';
import type { Container } from '../container';
import { PullRequestNode } from '../views/nodes';
import { Command, command, CommandContext, Commands } from './common';
@ -13,7 +13,7 @@ export interface OpenPullRequestOnRemoteCommandArgs {
@command()
export class OpenPullRequestOnRemoteCommand extends Command {
constructor() {
constructor(private readonly container: Container) {
super([Commands.OpenPullRequestOnRemote, Commands.CopyRemotePullRequestUrl]);
}
@ -33,10 +33,10 @@ export class OpenPullRequestOnRemoteCommand extends Command {
if (args?.pr == null) {
if (args?.repoPath == null || args?.ref == null) return;
const remote = await Container.instance.git.getRichRemoteProvider(args.repoPath);
const remote = await this.container.git.getRichRemoteProvider(args.repoPath);
if (remote?.provider == null) return;
const pr = await Container.instance.git.getPullRequestForCommit(args.ref, remote.provider);
const pr = await this.container.git.getPullRequestForCommit(args.ref, remote.provider);
if (pr == null) return;
args = { ...args };

+ 2
- 1
src/commands/openRepoOnRemote.ts View File

@ -1,5 +1,6 @@
'use strict';
import { TextEditor, Uri, window } from 'vscode';
import type { Container } from '../container';
import { GitUri } from '../git/gitUri';
import { RemoteResourceType } from '../git/remotes/provider';
import { Logger } from '../logger';
@ -22,7 +23,7 @@ export interface OpenRepoOnRemoteCommandArgs {
@command()
export class OpenRepoOnRemoteCommand extends ActiveEditorCommand {
constructor() {
constructor(private readonly container: Container) {
super([Commands.OpenRepoOnRemote, Commands.Deprecated_OpenRepoInRemote, Commands.CopyRemoteRepositoryUrl]);
}

+ 3
- 3
src/commands/openRevisionFile.ts View File

@ -1,7 +1,7 @@
'use strict';
import { TextDocumentShowOptions, TextEditor, Uri } from 'vscode';
import { FileAnnotationType } from '../configuration';
import { Container } from '../container';
import type { Container } from '../container';
import { GitUri } from '../git/gitUri';
import { Logger } from '../logger';
import { Messages } from '../messages';
@ -18,7 +18,7 @@ export interface OpenRevisionFileCommandArgs {
@command()
export class OpenRevisionFileCommand extends ActiveEditorCommand {
constructor() {
constructor(private readonly container: Container) {
super([Commands.OpenRevisionFile, Commands.OpenRevisionFileInDiffLeft, Commands.OpenRevisionFileInDiffRight]);
}
@ -36,7 +36,7 @@ export class OpenRevisionFileCommand extends ActiveEditorCommand {
try {
if (args.revisionUri == null) {
if (gitUri?.sha) {
const commit = await Container.instance.git.getCommit(gitUri.repoPath!, gitUri.sha);
const commit = await this.container.git.getCommit(gitUri.repoPath!, gitUri.sha);
args.revisionUri =
commit != null && commit.status === 'D'

+ 4
- 4
src/commands/openWorkingFile.ts View File

@ -1,7 +1,7 @@
'use strict';
import { Range, TextDocumentShowOptions, TextEditor, Uri, window } from 'vscode';
import { FileAnnotationType } from '../configuration';
import { Container } from '../container';
import type { Container } from '../container';
import { GitUri } from '../git/gitUri';
import { Logger } from '../logger';
import { Messages } from '../messages';
@ -16,7 +16,7 @@ export interface OpenWorkingFileCommandArgs {
@command()
export class OpenWorkingFileCommand extends ActiveEditorCommand {
constructor() {
constructor(private readonly container: Container) {
super([Commands.OpenWorkingFile, Commands.OpenWorkingFileInDiffLeft, Commands.OpenWorkingFileInDiffRight]);
}
@ -36,7 +36,7 @@ export class OpenWorkingFileCommand extends ActiveEditorCommand {
args.uri = await GitUri.fromUri(uri);
if (GitUri.is(args.uri) && args.uri.sha) {
const workingUri = await Container.instance.git.getWorkingUri(args.uri.repoPath!, args.uri);
const workingUri = await this.container.git.getWorkingUri(args.uri.repoPath!, args.uri);
if (workingUri === undefined) {
void window.showWarningMessage(
'Unable to open working file. File could not be found in the working tree',
@ -58,7 +58,7 @@ export class OpenWorkingFileCommand extends ActiveEditorCommand {
const e = await findOrOpenEditor(args.uri, { ...args.showOptions, throwOnError: true });
if (args.annotationType === undefined) return;
void (await Container.instance.fileAnnotations.show(e, args.annotationType, {
void (await this.container.fileAnnotations.show(e, args.annotationType, {
selection: { line: args.line },
}));
} catch (ex) {

+ 3
- 2
src/commands/quickCommand.ts View File

@ -1,6 +1,6 @@
'use strict';
import { InputBox, QuickInputButton, QuickPick, QuickPickItem } from 'vscode';
import { Container } from '../container';
import type { Container } from '../container';
import { Keys } from '../keyboard';
import { Directive, DirectiveQuickPickItem } from '../quickpicks';
@ -102,6 +102,7 @@ export abstract class QuickCommand implements QuickPickItem {
private _stepsIterator: StepGenerator | undefined;
constructor(
protected readonly container: Container,
public readonly key: string,
public readonly label: string,
public readonly title: string,
@ -154,7 +155,7 @@ export abstract class QuickCommand implements QuickPickItem {
return override != null
? override
: !Container.instance.config.gitCommands.skipConfirmations.includes(this.skipConfirmKey);
: !this.container.config.gitCommands.skipConfirmations.includes(this.skipConfirmKey);
}
isMatch(key: string) {

+ 5
- 5
src/commands/rebaseEditor.ts View File

@ -1,25 +1,25 @@
'use strict';
import { Container } from '../container';
import type { Container } from '../container';
import { command, Command, Commands } from './common';
@command()
export class DisableRebaseEditorCommand extends Command {
constructor() {
constructor(private readonly container: Container) {
super(Commands.DisableRebaseEditor);
}
execute() {
return Container.instance.rebaseEditor.setEnabled(false);
return this.container.rebaseEditor.setEnabled(false);
}
}
@command()
export class EnableRebaseEditorCommand extends Command {
constructor() {
constructor(private readonly container: Container) {
super(Commands.EnableRebaseEditor);
}
execute() {
return Container.instance.rebaseEditor.setEnabled(true);
return this.container.rebaseEditor.setEnabled(true);
}
}

+ 2
- 1
src/commands/refreshHover.ts View File

@ -1,10 +1,11 @@
'use strict';
import { commands } from 'vscode';
import type { Container } from '../container';
import { command, Command, Commands } from './common';
@command()
export class RefreshHoverCommand extends Command {
constructor() {
constructor(private readonly container: Container) {
super(Commands.RefreshHover);
}

+ 10
- 10
src/commands/remoteProviders.ts View File

@ -1,5 +1,5 @@
'use strict';
import { Container } from '../container';
import type { Container } from '../container';
import { GitCommit, GitRemote, Repository } from '../git/models';
import { RichRemoteProvider } from '../git/remotes/provider';
import { RepositoryPicker } from '../quickpicks/repositoryPicker';
@ -29,7 +29,7 @@ export class ConnectRemoteProviderCommand extends Command {
return super.getMarkdownCommandArgsCore<ConnectRemoteProviderCommandArgs>(Commands.ConnectRemoteProvider, args);
}
constructor() {
constructor(private readonly container: Container) {
super(Commands.ConnectRemoteProvider);
}
@ -48,7 +48,7 @@ export class ConnectRemoteProviderCommand extends Command {
if (args?.repoPath == null) {
const repos = new Map<Repository, GitRemote<RichRemoteProvider>>();
for (const repo of Container.instance.git.openRepositories) {
for (const repo of this.container.git.openRepositories) {
const remote = await repo.getRichRemote();
if (remote?.provider != null && !(await remote.provider.isConnected())) {
repos.set(repo, remote);
@ -74,18 +74,18 @@ export class ConnectRemoteProviderCommand extends Command {
} else if (args?.remote == null) {
repoPath = args.repoPath;
remote = await Container.instance.git.getRichRemoteProvider(repoPath, { includeDisconnected: true });
remote = await this.container.git.getRichRemoteProvider(repoPath, { includeDisconnected: true });
if (remote == null) return false;
} else {
repoPath = args.repoPath;
remotes = await Container.instance.git.getRemotes(repoPath);
remotes = await this.container.git.getRemotes(repoPath);
remote = remotes.find(r => r.id === args.remote) as GitRemote<RichRemoteProvider> | undefined;
if (!remote?.hasRichProvider()) return false;
}
const connected = await remote.provider.connect();
if (connected && !(remotes ?? (await Container.instance.git.getRemotes(repoPath))).some(r => r.default)) {
if (connected && !(remotes ?? (await this.container.git.getRemotes(repoPath))).some(r => r.default)) {
await remote.setAsDefault(true);
}
return connected;
@ -118,7 +118,7 @@ export class DisconnectRemoteProviderCommand extends Command {
);
}
constructor() {
constructor(private readonly container: Container) {
super(Commands.DisconnectRemoteProvider);
}
@ -136,7 +136,7 @@ export class DisconnectRemoteProviderCommand extends Command {
if (args?.repoPath == null) {
const repos = new Map<Repository, GitRemote<RichRemoteProvider>>();
for (const repo of Container.instance.git.openRepositories) {
for (const repo of this.container.git.openRepositories) {
const remote = await repo.getRichRemote(true);
if (remote != null) {
repos.set(repo, remote);
@ -162,12 +162,12 @@ export class DisconnectRemoteProviderCommand extends Command {
} else if (args?.remote == null) {
repoPath = args.repoPath;
remote = await Container.instance.git.getRichRemoteProvider(repoPath, { includeDisconnected: false });
remote = await this.container.git.getRichRemoteProvider(repoPath, { includeDisconnected: false });
if (remote == null) return undefined;
} else {
repoPath = args.repoPath;
remote = (await Container.instance.git.getRemotes(repoPath)).find(r => r.id === args.remote) as
remote = (await this.container.git.getRemotes(repoPath)).find(r => r.id === args.remote) as
| GitRemote<RichRemoteProvider>
| undefined;
if (!remote?.hasRichProvider()) return undefined;

+ 7
- 7
src/commands/repositories.ts View File

@ -1,46 +1,46 @@
'use strict';
import { executeGitCommand } from '../commands';
import { Container } from '../container';
import type { Container } from '../container';
import { command, Command, Commands } from './common';
@command()
export class FetchRepositoriesCommand extends Command {
constructor() {
constructor(private readonly container: Container) {
super(Commands.FetchRepositories);
}
async execute() {
return executeGitCommand({
command: 'fetch',
state: { repos: Container.instance.git.openRepositories },
state: { repos: this.container.git.openRepositories },
});
}
}
@command()
export class PullRepositoriesCommand extends Command {
constructor() {
constructor(private readonly container: Container) {
super(Commands.PullRepositories);
}
async execute() {
return executeGitCommand({
command: 'pull',
state: { repos: Container.instance.git.openRepositories },
state: { repos: this.container.git.openRepositories },
});
}
}
@command()
export class PushRepositoriesCommand extends Command {
constructor() {
constructor(private readonly container: Container) {
super(Commands.PushRepositories);
}
async execute() {
return executeGitCommand({
command: 'push',
state: { repos: Container.instance.git.openRepositories },
state: { repos: this.container.git.openRepositories },
});
}
}

+ 2
- 1
src/commands/resetAvatarCache.ts View File

@ -1,10 +1,11 @@
'use strict';
import { resetAvatarCache } from '../avatars';
import type { Container } from '../container';
import { command, Command, Commands } from './common';
@command()
export class ResetAvatarCacheCommand extends Command {
constructor() {
constructor(private readonly container: Container) {
super(Commands.ResetAvatarCache);
}

+ 2
- 1
src/commands/resetSuppressedWarnings.ts View File

@ -1,11 +1,12 @@
'use strict';
import { ConfigurationTarget } from 'vscode';
import { configuration } from '../configuration';
import type { Container } from '../container';
import { command, Command, Commands } from './common';
@command()
export class ResetSuppressedWarningsCommand extends Command {
constructor() {
constructor(private readonly container: Container) {
super(Commands.ResetSuppressedWarnings);
}

+ 3
- 3
src/commands/searchCommits.ts View File

@ -1,6 +1,6 @@
'use strict';
import { executeGitCommand } from '../commands';
import { Container } from '../container';
import type { Container } from '../container';
import { SearchPattern } from '../git/search';
import { SearchResultsNode } from '../views/nodes';
import { Command, command, CommandContext, Commands, isCommandContextViewNodeHasRepository } from './common';
@ -16,7 +16,7 @@ export interface SearchCommitsCommandArgs {
@command()
export class SearchCommitsCommand extends Command {
constructor() {
constructor(private readonly container: Container) {
super([Commands.SearchCommits, Commands.SearchCommitsInView]);
}
@ -50,7 +50,7 @@ export class SearchCommitsCommand extends Command {
repo: args?.repoPath,
...args?.search,
showResultsInSideBar:
Container.instance.config.gitCommands.search.showResultsInSideBar ?? args?.showResultsInSideBar,
this.container.config.gitCommands.search.showResultsInSideBar ?? args?.showResultsInSideBar,
},
}));
}

+ 2
- 1
src/commands/setViewsLayout.ts View File

@ -1,6 +1,7 @@
'use strict';
import { commands, window } from 'vscode';
import { viewsConfigKeys } from '../configuration';
import type { Container } from '../container';
import { command, Command, Commands } from './common';
enum ViewsLayout {
@ -14,7 +15,7 @@ export interface SetViewsLayoutCommandArgs {
@command()
export class SetViewsLayoutCommand extends Command {
constructor() {
constructor(private readonly container: Container) {
super(Commands.SetViewsLayout);
}

+ 4
- 4
src/commands/showCommitsInView.ts View File

@ -1,7 +1,7 @@
'use strict';
import { TextEditor, Uri } from 'vscode';
import { executeGitCommand } from '../commands';
import { Container } from '../container';
import type { Container } from '../container';
import { GitUri } from '../git/gitUri';
import { SearchPattern } from '../git/search';
import { Logger } from '../logger';
@ -16,7 +16,7 @@ export interface ShowCommitsInViewCommandArgs {
@command()
export class ShowCommitsInViewCommand extends ActiveEditorCommand {
constructor() {
constructor(private readonly container: Container) {
super([Commands.ShowCommitInView, Commands.ShowCommitsInView]);
}
@ -35,12 +35,12 @@ export class ShowCommitsInViewCommand extends ActiveEditorCommand {
try {
// Check for any uncommitted changes in the range
const blame = editor.document.isDirty
? await Container.instance.git.getBlameForRangeContents(
? await this.container.git.getBlameForRangeContents(
gitUri,
editor.selection,
editor.document.getText(),
)
: await Container.instance.git.getBlameForRange(gitUri, editor.selection);
: await this.container.git.getBlameForRange(gitUri, editor.selection);
if (blame === undefined) {
return Messages.showFileNotUnderSourceControlWarningMessage('Unable to find commits');
}

+ 2
- 1
src/commands/showLastQuickPick.ts View File

@ -1,12 +1,13 @@
'use strict';
import { commands } from 'vscode';
import type { Container } from '../container';
import { Logger } from '../logger';
import { Messages } from '../messages';
import { command, Command, Commands, getLastCommand } from './common';
@command()
export class ShowLastQuickPickCommand extends Command {
constructor() {
constructor(private readonly container: Container) {
super(Commands.ShowLastQuickPick);
}

+ 3
- 3
src/commands/showQuickBranchHistory.ts View File

@ -1,6 +1,6 @@
'use strict';
import { TextEditor, Uri } from 'vscode';
import { Container } from '../container';
import type { Container } from '../container';
import { GitUri } from '../git/gitUri';
import { GitReference } from '../git/models';
import { ActiveEditorCachedCommand, command, CommandContext, Commands, getCommandUri } from './common';
@ -14,7 +14,7 @@ export interface ShowQuickBranchHistoryCommandArgs {
@command()
export class ShowQuickBranchHistoryCommand extends ActiveEditorCachedCommand {
constructor() {
constructor(private readonly container: Container) {
super([Commands.ShowQuickBranchHistory, Commands.ShowQuickCurrentBranchHistory]);
}
@ -32,7 +32,7 @@ export class ShowQuickBranchHistoryCommand extends ActiveEditorCachedCommand {
const gitUri = uri != null ? await GitUri.fromUri(uri) : undefined;
const repoPath = args?.repoPath ?? gitUri?.repoPath ?? Container.instance.git.highlanderRepoPath;
const repoPath = args?.repoPath ?? gitUri?.repoPath ?? this.container.git.highlanderRepoPath;
let ref: GitReference | 'HEAD' | undefined;
if (repoPath != null) {
if (args?.branch != null) {

+ 4
- 4
src/commands/showQuickCommit.ts View File

@ -1,6 +1,6 @@
'use strict';
import { TextEditor, Uri } from 'vscode';
import { Container } from '../container';
import type { Container } from '../container';
import { GitUri } from '../git/gitUri';
import { GitCommit, GitLog, GitLogCommit } from '../git/models';
import { Logger } from '../logger';
@ -32,7 +32,7 @@ export class ShowQuickCommitCommand extends ActiveEditorCachedCommand {
return super.getMarkdownCommandArgsCore<ShowQuickCommitCommandArgs>(Commands.ShowQuickCommit, args);
}
constructor() {
constructor(private readonly container: Container) {
super([Commands.RevealCommitInView, Commands.ShowQuickCommit]);
}
@ -89,7 +89,7 @@ export class ShowQuickCommitCommand extends ActiveEditorCachedCommand {
if (blameline < 0) return;
try {
const blame = await Container.instance.git.getBlameForLine(gitUri, blameline);
const blame = await this.container.git.getBlameForLine(gitUri, blameline);
if (blame == null) {
void Messages.showFileNotUnderSourceControlWarningMessage('Unable to show commit');
@ -126,7 +126,7 @@ export class ShowQuickCommitCommand extends ActiveEditorCachedCommand {
}
if (args.repoLog == null) {
args.commit = await Container.instance.git.getCommit(repoPath!, args.sha);
args.commit = await this.container.git.getCommit(repoPath!, args.sha);
}
}

+ 5
- 5
src/commands/showQuickCommitFile.ts View File

@ -1,6 +1,6 @@
'use strict';
import { TextEditor, Uri, window } from 'vscode';
import { Container } from '../container';
import type { Container } from '../container';
import { GitUri } from '../git/gitUri';
import { GitBlameCommit, GitCommit, GitLog, GitLogCommit } from '../git/models';
import { Logger } from '../logger';
@ -28,7 +28,7 @@ export class ShowQuickCommitFileCommand extends ActiveEditorCachedCommand {
return super.getMarkdownCommandArgsCore<ShowQuickCommitFileCommandArgs>(Commands.ShowQuickCommitFile, args);
}
constructor() {
constructor(private readonly container: Container) {
super([
Commands.ShowQuickCommitFile,
Commands.ShowQuickCommitRevision,
@ -78,7 +78,7 @@ export class ShowQuickCommitFileCommand extends ActiveEditorCachedCommand {
if (blameline < 0) return;
try {
const blame = await Container.instance.git.getBlameForLine(gitUri, blameline);
const blame = await this.container.git.getBlameForLine(gitUri, blameline);
if (blame == null) {
void Messages.showFileNotUnderSourceControlWarningMessage('Unable to show commit file details');
@ -115,7 +115,7 @@ export class ShowQuickCommitFileCommand extends ActiveEditorCachedCommand {
if (args.fileLog === undefined) {
const repoPath = args.commit === undefined ? gitUri.repoPath : args.commit.repoPath;
args.commit = await Container.instance.git.getCommitForFile(repoPath, gitUri, {
args.commit = await this.container.git.getCommitForFile(repoPath, gitUri, {
ref: args.sha,
});
if (args.commit === undefined) {
@ -136,7 +136,7 @@ export class ShowQuickCommitFileCommand extends ActiveEditorCachedCommand {
const fileName = args.commit.fileName;
if (args.commit instanceof GitBlameCommit) {
args.commit = (await Container.instance.git.getCommit(args.commit.repoPath, args.commit.ref))!;
args.commit = (await this.container.git.getCommit(args.commit.repoPath, args.commit.ref))!;
}
void (await executeGitCommand({

+ 3
- 3
src/commands/showQuickFileHistory.ts View File

@ -1,6 +1,6 @@
'use strict';
import { Range, TextEditor, Uri } from 'vscode';
import { Container } from '../container';
import type { Container } from '../container';
import { GitUri } from '../git/gitUri';
import { GitBranch, GitLog, GitReference, GitTag } from '../git/models';
import { CommandQuickPickItem } from '../quickpicks';
@ -20,7 +20,7 @@ export interface ShowQuickFileHistoryCommandArgs {
@command()
export class ShowQuickFileHistoryCommand extends ActiveEditorCachedCommand {
constructor() {
constructor(private readonly container: Container) {
super([
Commands.OpenFileHistory,
Commands.OpenFolderHistory,
@ -50,7 +50,7 @@ export class ShowQuickFileHistoryCommand extends ActiveEditorCachedCommand {
const gitUri = await GitUri.fromUri(uri);
if (args?.showInSideBar) {
await Container.instance.fileHistoryView.showHistoryForUri(gitUri);
await this.container.fileHistoryView.showHistoryForUri(gitUri);
return;
}

+ 2
- 1
src/commands/showQuickRepoStatus.ts View File

@ -1,5 +1,6 @@
'use strict';
import { executeGitCommand } from '../commands';
import type { Container } from '../container';
import { Command, command, Commands } from './common';
export interface ShowQuickRepoStatusCommandArgs {
@ -8,7 +9,7 @@ export interface ShowQuickRepoStatusCommandArgs {
@command()
export class ShowQuickRepoStatusCommand extends Command {
constructor() {
constructor(private readonly container: Container) {
super(Commands.ShowQuickRepoStatus);
}

+ 2
- 1
src/commands/showQuickStashList.ts View File

@ -1,5 +1,6 @@
'use strict';
import { executeGitCommand } from '../commands';
import type { Container } from '../container';
import { Command, command, Commands } from './common';
export interface ShowQuickStashListCommandArgs {
@ -8,7 +9,7 @@ export interface ShowQuickStashListCommandArgs {
@command()
export class ShowQuickStashListCommand extends Command {
constructor() {
constructor(private readonly container: Container) {
super(Commands.ShowQuickStashList);
}

+ 13
- 13
src/commands/showView.ts View File

@ -1,12 +1,12 @@
'use strict';
import { commands } from 'vscode';
import { ContextKeys, setContext, SyncedState } from '../constants';
import { Container } from '../container';
import type { Container } from '../container';
import { command, Command, CommandContext, Commands } from './common';
@command()
export class ShowViewCommand extends Command {
constructor() {
constructor(private readonly container: Container) {
super([
Commands.ShowBranchesView,
Commands.ShowCommitsView,
@ -29,28 +29,28 @@ export class ShowViewCommand extends Command {
async execute(command: Commands) {
switch (command) {
case Commands.ShowBranchesView:
return Container.instance.branchesView.show();
return this.container.branchesView.show();
case Commands.ShowCommitsView:
return Container.instance.commitsView.show();
return this.container.commitsView.show();
case Commands.ShowContributorsView:
return Container.instance.contributorsView.show();
return this.container.contributorsView.show();
case Commands.ShowFileHistoryView:
return Container.instance.fileHistoryView.show();
return this.container.fileHistoryView.show();
case Commands.ShowLineHistoryView:
return Container.instance.lineHistoryView.show();
return this.container.lineHistoryView.show();
case Commands.ShowRemotesView:
return Container.instance.remotesView.show();
return this.container.remotesView.show();
case Commands.ShowRepositoriesView:
return Container.instance.repositoriesView.show();
return this.container.repositoriesView.show();
case Commands.ShowSearchAndCompareView:
return Container.instance.searchAndCompareView.show();
return this.container.searchAndCompareView.show();
case Commands.ShowStashesView:
return Container.instance.stashesView.show();
return this.container.stashesView.show();
case Commands.ShowTagsView:
return Container.instance.tagsView.show();
return this.container.tagsView.show();
case Commands.ShowWelcomeView:
await setContext(ContextKeys.ViewsWelcomeVisible, true);
void Container.instance.context.globalState.update(SyncedState.WelcomeViewVisible, true);
void this.container.context.globalState.update(SyncedState.WelcomeViewVisible, true);
void (await commands.executeCommand('gitlens.views.welcome.focus'));
}

+ 2
- 1
src/commands/stashApply.ts View File

@ -1,5 +1,6 @@
'use strict';
import { GitActions } from '../commands';
import type { Container } from '../container';
import { GitStashCommit, GitStashReference } from '../git/models';
import { CommandQuickPickItem } from '../quickpicks';
import {
@ -21,7 +22,7 @@ export interface StashApplyCommandArgs {
@command()
export class StashApplyCommand extends Command {
constructor() {
constructor(private readonly container: Container) {
super(Commands.StashApply);
}

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

@ -3,7 +3,7 @@ import { Uri } from 'vscode';
import type { ScmResource } from '../@types/vscode.git.resources';
import { ScmResourceGroupType } from '../@types/vscode.git.resources.enums';
import { GitActions } from '../commands';
import { Container } from '../container';
import type { Container } from '../container';
import { GitUri } from '../git/gitUri';
import {
Command,
@ -24,7 +24,7 @@ export interface StashSaveCommandArgs {
@command()
export class StashSaveCommand extends Command {
constructor() {
constructor(private readonly container: Container) {
super([Commands.StashSave, Commands.StashSaveFiles]);
}
@ -42,9 +42,9 @@ export class StashSaveCommand extends Command {
} else if (context.type === 'scm-states') {
args = { ...args };
args.uris = context.scmResourceStates.map(s => s.resourceUri);
args.repoPath = await Container.instance.git.getRepoPath(args.uris[0].fsPath);
args.repoPath = await this.container.git.getRepoPath(args.uris[0].fsPath);
const status = await Container.instance.git.getStatusForRepo(args.repoPath);
const status = await this.container.git.getStatusForRepo(args.repoPath);
if (status?.computeWorkingTreeStatus().staged) {
if (
!context.scmResourceStates.some(
@ -60,9 +60,9 @@ export class StashSaveCommand extends Command {
(a, b) => a.concat(b.resourceStates.map(s => s.resourceUri)),
[],
);
args.repoPath = await Container.instance.git.getRepoPath(args.uris[0].fsPath);
args.repoPath = await this.container.git.getRepoPath(args.uris[0].fsPath);
const status = await Container.instance.git.getStatusForRepo(args.repoPath);
const status = await this.container.git.getStatusForRepo(args.repoPath);
if (status?.computeWorkingTreeStatus().staged) {
if (!context.scmResourceGroups.some(g => g.id === 'index')) {
args.keepStaged = true;

+ 12
- 15
src/commands/switchMode.ts View File

@ -1,7 +1,7 @@
'use strict';
import { ConfigurationTarget } from 'vscode';
import { configuration } from '../configuration';
import { Container } from '../container';
import type { Container } from '../container';
import { Logger } from '../logger';
import { ModePicker } from '../quickpicks';
import { log } from '../system';
@ -9,7 +9,7 @@ import { command, Command, Commands } from './common';
@command()
export class SwitchModeCommand extends Command {
constructor() {
constructor(private readonly container: Container) {
super(Commands.SwitchMode);
}
@ -24,17 +24,17 @@ export class SwitchModeCommand extends Command {
cc.exitDetails = ` \u2014 mode=${pick.key ?? ''}`;
}
const active = Container.instance.config.mode.active;
const active = this.container.config.mode.active;
if (active === pick.key) return;
// Check if we have applied any annotations and clear them if we won't be applying them again
if (active != null && active.length !== 0) {
const activeAnnotations = Container.instance.config.modes?.[active].annotations;
const activeAnnotations = this.container.config.modes?.[active].annotations;
if (activeAnnotations != null) {
const newAnnotations =
pick.key != null ? Container.instance.config.modes?.[pick.key].annotations : undefined;
pick.key != null ? this.container.config.modes?.[pick.key].annotations : undefined;
if (activeAnnotations !== newAnnotations) {
await Container.instance.fileAnnotations.clearAll();
await this.container.fileAnnotations.clearAll();
}
}
}
@ -45,37 +45,34 @@ export class SwitchModeCommand extends Command {
@command()
export class ToggleReviewModeCommand extends Command {
constructor() {
constructor(private readonly container: Container) {
super(Commands.ToggleReviewMode);
}
@log({ args: false, singleLine: true, timed: false })
async execute() {
if (
Container.instance.config.modes == null ||
!Object.keys(Container.instance.config.modes).includes('review')
) {
if (this.container.config.modes == null || !Object.keys(this.container.config.modes).includes('review')) {
return;
}
const mode = Container.instance.config.mode.active === 'review' ? undefined : 'review';
const mode = this.container.config.mode.active === 'review' ? undefined : 'review';
await configuration.update('mode.active', mode, ConfigurationTarget.Global);
}
}
@command()
export class ToggleZenModeCommand extends Command {
constructor() {
constructor(private readonly container: Container) {
super(Commands.ToggleZenMode);
}
@log({ args: false, singleLine: true, timed: false })
async execute() {
if (Container.instance.config.modes == null || !Object.keys(Container.instance.config.modes).includes('zen')) {
if (this.container.config.modes == null || !Object.keys(this.container.config.modes).includes('zen')) {
return;
}
const mode = Container.instance.config.mode.active === 'zen' ? undefined : 'zen';
const mode = this.container.config.mode.active === 'zen' ? undefined : 'zen';
await configuration.update('mode.active', mode, ConfigurationTarget.Global);
}
}

+ 3
- 3
src/commands/toggleCodeLens.ts View File

@ -1,14 +1,14 @@
'use strict';
import { Container } from '../container';
import type { Container } from '../container';
import { command, Command, Commands } from './common';
@command()
export class ToggleCodeLensCommand extends Command {
constructor() {
constructor(private readonly container: Container) {
super(Commands.ToggleCodeLens);
}
execute() {
return Container.instance.codeLens.toggleCodeLens();
return this.container.codeLens.toggleCodeLens();
}
}

+ 11
- 10
src/commands/toggleFileAnnotations.ts View File

@ -5,14 +5,14 @@ import { ChangesAnnotationContext } from '../annotations/gutterChangesAnnotation
import { UriComparer } from '../comparers';
import { FileAnnotationType } from '../configuration';
import { isTextEditor } from '../constants';
import { Container } from '../container';
import type { Container } from '../container';
import { Logger } from '../logger';
import { Messages } from '../messages';
import { ActiveEditorCommand, command, Commands, EditorCommand } from './common';
@command()
export class ClearFileAnnotationsCommand extends EditorCommand {
constructor() {
constructor(private readonly container: Container) {
super([Commands.ClearFileAnnotations, Commands.ComputingFileAnnotations]);
}
@ -28,7 +28,7 @@ export class ClearFileAnnotationsCommand extends EditorCommand {
}
try {
void (await Container.instance.fileAnnotations.clear(editor));
void (await this.container.fileAnnotations.clear(editor));
} catch (ex) {
Logger.error(ex, 'ClearFileAnnotationsCommand');
void Messages.showGenericErrorMessage('Unable to clear file annotations');
@ -61,12 +61,12 @@ export type ToggleFileAnnotationCommandArgs =
@command()
export class ToggleFileBlameCommand extends ActiveEditorCommand {
constructor() {
constructor(private readonly container: Container) {
super([Commands.ToggleFileBlame, Commands.ToggleFileBlameInDiffLeft, Commands.ToggleFileBlameInDiffRight]);
}
execute(editor: TextEditor, uri?: Uri, args?: ToggleFileBlameAnnotationCommandArgs): Promise<void> {
return toggleFileAnnotations<ToggleFileBlameAnnotationCommandArgs>(editor, uri, {
return toggleFileAnnotations<ToggleFileBlameAnnotationCommandArgs>(this.container, editor, uri, {
...args,
type: FileAnnotationType.Blame,
});
@ -75,12 +75,12 @@ export class ToggleFileBlameCommand extends ActiveEditorCommand {
@command()
export class ToggleFileChangesCommand extends ActiveEditorCommand {
constructor() {
constructor(private readonly container: Container) {
super(Commands.ToggleFileChanges);
}
execute(editor: TextEditor, uri?: Uri, args?: ToggleFileChangesAnnotationCommandArgs): Promise<void> {
return toggleFileAnnotations<ToggleFileChangesAnnotationCommandArgs>(editor, uri, {
return toggleFileAnnotations<ToggleFileChangesAnnotationCommandArgs>(this.container, editor, uri, {
...args,
type: FileAnnotationType.Changes,
});
@ -89,7 +89,7 @@ export class ToggleFileChangesCommand extends ActiveEditorCommand {
@command()
export class ToggleFileHeatmapCommand extends ActiveEditorCommand {
constructor() {
constructor(private readonly container: Container) {
super([
Commands.ToggleFileHeatmap,
Commands.ToggleFileHeatmapInDiffLeft,
@ -98,7 +98,7 @@ export class ToggleFileHeatmapCommand extends ActiveEditorCommand {
}
execute(editor: TextEditor, uri?: Uri, args?: ToggleFileHeatmapAnnotationCommandArgs): Promise<void> {
return toggleFileAnnotations<ToggleFileHeatmapAnnotationCommandArgs>(editor, uri, {
return toggleFileAnnotations<ToggleFileHeatmapAnnotationCommandArgs>(this.container, editor, uri, {
...args,
type: FileAnnotationType.Heatmap,
});
@ -106,6 +106,7 @@ export class ToggleFileHeatmapCommand extends ActiveEditorCommand {
}
async function toggleFileAnnotations<TArgs extends ToggleFileAnnotationCommandArgs>(
container: Container,
editor: TextEditor,
uri: Uri | undefined,
args: TArgs,
@ -123,7 +124,7 @@ async function toggleFileAnnotations
try {
args = { type: FileAnnotationType.Blame, ...(args as any) };
void (await Container.instance.fileAnnotations.toggle(
void (await container.fileAnnotations.toggle(
editor,
args.type,
{

+ 3
- 3
src/commands/toggleLineBlame.ts View File

@ -1,17 +1,17 @@
import { TextEditor, Uri, window } from 'vscode';
import { Container } from '../container';
import type { Container } from '../container';
import { Logger } from '../logger';
import { ActiveEditorCommand, command, Commands } from './common';
@command()
export class ToggleLineBlameCommand extends ActiveEditorCommand {
constructor() {
constructor(private readonly container: Container) {
super(Commands.ToggleLineBlame);
}
async execute(editor: TextEditor, _uri?: Uri): Promise<void> {
try {
void (await Container.instance.lineAnnotations.toggle(editor));
void (await this.container.lineAnnotations.toggle(editor));
} catch (ex) {
Logger.error(ex, 'ToggleLineBlameCommand');
void window.showErrorMessage(

+ 1
- 1
src/extension.ts View File

@ -98,7 +98,7 @@ export function activate(context: ExtensionContext): Promise
const container = Container.create(context, cfg);
container.onReady(() => {
registerCommands(context);
context.subscriptions.push(...registerCommands(container));
registerBuiltInActionRunners(container);
registerPartnerActionRunners(context);

+ 2
- 1
src/quickpicks/gitQuickPickItems.ts View File

@ -2,6 +2,7 @@
import { QuickInputButton, QuickPickItem } from 'vscode';
import { Commands, GitCommandsCommand, GitCommandsCommandArgs } from '../commands';
import { GlyphChars } from '../constants';
import { Container } from '../container';
import { emojify } from '../emojis';
import {
GitBranch,
@ -25,7 +26,7 @@ export class GitCommandQuickPickItem extends CommandQuickPickItem<[GitCommandsCo
}
executeSteps(pickedVia: 'menu' | 'command') {
return GitCommandsCommand.getSteps(this.args![0], pickedVia);
return GitCommandsCommand.getSteps(Container.instance, this.args![0], pickedVia);
}
}

Loading…
Cancel
Save