diff --git a/src/commands/closeUnchangedFiles.ts b/src/commands/closeUnchangedFiles.ts index c7df8ec..57f71f6 100644 --- a/src/commands/closeUnchangedFiles.ts +++ b/src/commands/closeUnchangedFiles.ts @@ -9,7 +9,7 @@ import * as path from 'path'; export class CloseUnchangedFilesCommand extends ActiveEditorCommand { - constructor(private git: GitService, private repoPath: string) { + constructor(private git: GitService) { super(Commands.CloseUnchangedFiles); } @@ -20,7 +20,7 @@ export class CloseUnchangedFilesCommand extends ActiveEditorCommand { try { if (!uris) { - const repoPath = await this.git.getRepoPathFromUri(uri, this.repoPath); + const repoPath = await this.git.getRepoPathFromUri(uri, this.git.repoPath); if (!repoPath) return window.showWarningMessage(`Unable to close unchanged files`); const status = await this.git.getStatusForRepo(repoPath); diff --git a/src/commands/copyMessageToClipboard.ts b/src/commands/copyMessageToClipboard.ts index 8e8bcb7..97f5a7c 100644 --- a/src/commands/copyMessageToClipboard.ts +++ b/src/commands/copyMessageToClipboard.ts @@ -8,7 +8,7 @@ import { copy } from 'copy-paste'; export class CopyMessageToClipboardCommand extends ActiveEditorCommand { - constructor(private git: GitService, private repoPath: string) { + constructor(private git: GitService) { super(Commands.CopyMessageToClipboard); } @@ -20,7 +20,7 @@ export class CopyMessageToClipboardCommand extends ActiveEditorCommand { try { // If we don't have an editor then get the message of the last commit to the branch if (!uri) { - const log = await this.git.getLogForRepo(this.repoPath, undefined, 1); + const log = await this.git.getLogForRepo(this.git.repoPath, undefined, 1); if (!log) return undefined; message = Iterables.first(log.commits.values()).message; diff --git a/src/commands/copyShaToClipboard.ts b/src/commands/copyShaToClipboard.ts index 01ce8c7..b106f8c 100644 --- a/src/commands/copyShaToClipboard.ts +++ b/src/commands/copyShaToClipboard.ts @@ -8,7 +8,7 @@ import { copy } from 'copy-paste'; export class CopyShaToClipboardCommand extends ActiveEditorCommand { - constructor(private git: GitService, private repoPath: string) { + constructor(private git: GitService) { super(Commands.CopyShaToClipboard); } @@ -20,7 +20,7 @@ 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) { - const log = await this.git.getLogForRepo(this.repoPath, undefined, 1); + const log = await this.git.getLogForRepo(this.git.repoPath, undefined, 1); if (!log) return undefined; sha = Iterables.first(log.commits.values()).sha; diff --git a/src/commands/diffDirectory.ts b/src/commands/diffDirectory.ts index 8246916..93a1850 100644 --- a/src/commands/diffDirectory.ts +++ b/src/commands/diffDirectory.ts @@ -8,7 +8,7 @@ import { CommandQuickPickItem, BranchesQuickPick } from '../quickPicks'; export class DiffDirectoryCommand extends ActiveEditorCommand { - constructor(private git: GitService, private repoPath: string) { + constructor(private git: GitService) { super(Commands.DiffDirectory); } @@ -18,7 +18,7 @@ export class DiffDirectoryCommand extends ActiveEditorCommand { } try { - const repoPath = await this.git.getRepoPathFromUri(uri, this.repoPath); + const repoPath = await this.git.getRepoPathFromUri(uri, this.git.repoPath); if (!repoPath) return window.showWarningMessage(`Unable to open directory diff`); if (!shaOrBranch1) { diff --git a/src/commands/openChangedFiles.ts b/src/commands/openChangedFiles.ts index 3a08fda..08d2837 100644 --- a/src/commands/openChangedFiles.ts +++ b/src/commands/openChangedFiles.ts @@ -7,7 +7,7 @@ import * as path from 'path'; export class OpenChangedFilesCommand extends ActiveEditorCommand { - constructor(private git: GitService, private repoPath: string) { + constructor(private git: GitService) { super(Commands.OpenChangedFiles); } @@ -18,7 +18,7 @@ export class OpenChangedFilesCommand extends ActiveEditorCommand { try { if (!uris) { - const repoPath = await this.git.getRepoPathFromUri(uri, this.repoPath); + const repoPath = await this.git.getRepoPathFromUri(uri, this.git.repoPath); if (!repoPath) return window.showWarningMessage(`Unable to open changed files`); const status = await this.git.getStatusForRepo(repoPath); diff --git a/src/commands/openCommitInRemote.ts b/src/commands/openCommitInRemote.ts index 53cdf31..05edac9 100644 --- a/src/commands/openCommitInRemote.ts +++ b/src/commands/openCommitInRemote.ts @@ -7,7 +7,7 @@ import { Logger } from '../logger'; export class OpenCommitInRemoteCommand extends ActiveEditorCommand { - constructor(private git: GitService, private repoPath: string) { + constructor(private git: GitService) { super(Commands.OpenCommitInRemote); } @@ -35,7 +35,7 @@ export class OpenCommitInRemoteCommand extends ActiveEditorCommand { commit = new GitCommit(commit.type, commit.repoPath, commit.previousSha, commit.previousFileName, commit.author, commit.date, commit.message); } - const remotes = Arrays.uniqueBy(await this.git.getRemotes(this.repoPath), _ => _.url, _ => !!_.provider); + const remotes = Arrays.uniqueBy(await this.git.getRemotes(this.git.repoPath), _ => _.url, _ => !!_.provider); return commands.executeCommand(Commands.OpenInRemote, uri, remotes, 'commit', [commit.sha]); } catch (ex) { diff --git a/src/commands/openFileInRemote.ts b/src/commands/openFileInRemote.ts index aafb83c..efc60b4 100644 --- a/src/commands/openFileInRemote.ts +++ b/src/commands/openFileInRemote.ts @@ -7,7 +7,7 @@ import { Logger } from '../logger'; export class OpenFileInRemoteCommand extends ActiveEditorCommand { - constructor(private git: GitService, private repoPath: string) { + constructor(private git: GitService) { super(Commands.OpenFileInRemote); } @@ -18,10 +18,10 @@ export class OpenFileInRemoteCommand extends ActiveEditorCommand { } const gitUri = await GitUri.fromUri(uri, this.git); - const branch = await this.git.getBranch(gitUri.repoPath || this.repoPath); + const branch = await this.git.getBranch(gitUri.repoPath || this.git.repoPath); try { - const remotes = Arrays.uniqueBy(await this.git.getRemotes(this.repoPath), _ => _.url, _ => !!_.provider); + const remotes = Arrays.uniqueBy(await this.git.getRemotes(this.git.repoPath), _ => _.url, _ => !!_.provider); const range = editor && new Range(editor.selection.start.with({ line: editor.selection.start.line + 1 }), editor.selection.end.with({ line: editor.selection.end.line + 1 })); return commands.executeCommand(Commands.OpenInRemote, uri, remotes, 'file', [gitUri.getRelativePath(), branch.name, gitUri.sha, range]); } diff --git a/src/commands/showQuickBranchHistory.ts b/src/commands/showQuickBranchHistory.ts index e7c4af2..1edeb9c 100644 --- a/src/commands/showQuickBranchHistory.ts +++ b/src/commands/showQuickBranchHistory.ts @@ -7,7 +7,7 @@ import { BranchesQuickPick, BranchHistoryQuickPick, CommandQuickPickItem } from export class ShowQuickBranchHistoryCommand extends ActiveEditorCachedCommand { - constructor(private git: GitService, private repoPath: string) { + constructor(private git: GitService) { super(Commands.ShowQuickBranchHistory); } @@ -24,7 +24,7 @@ export class ShowQuickBranchHistoryCommand extends ActiveEditorCachedCommand { let progressCancellation = branch && BranchHistoryQuickPick.showProgress(branch); try { - const repoPath = (gitUri && gitUri.repoPath) || await this.git.getRepoPathFromUri(uri, this.repoPath); + const repoPath = (gitUri && gitUri.repoPath) || await this.git.getRepoPathFromUri(uri, this.git.repoPath); if (!repoPath) return window.showWarningMessage(`Unable to show branch history`); if (!branch) { diff --git a/src/commands/showQuickCommitDetails.ts b/src/commands/showQuickCommitDetails.ts index d91d670..c41c395 100644 --- a/src/commands/showQuickCommitDetails.ts +++ b/src/commands/showQuickCommitDetails.ts @@ -8,7 +8,7 @@ import * as path from 'path'; export class ShowQuickCommitDetailsCommand extends ActiveEditorCachedCommand { - constructor(private git: GitService, private repoPath: string) { + constructor(private git: GitService) { super(Commands.ShowQuickCommitDetails); } @@ -56,7 +56,7 @@ export class ShowQuickCommitDetailsCommand extends ActiveEditorCachedCommand { } if (!repoLog) { - const log = await this.git.getLogForRepo(repoPath || this.repoPath, sha, 2); + const log = await this.git.getLogForRepo(repoPath || this.git.repoPath, sha, 2); if (!log) return window.showWarningMessage(`Unable to show commit details`); commit = log.commits.get(sha); diff --git a/src/commands/showQuickRepoStatus.ts b/src/commands/showQuickRepoStatus.ts index 305f0a3..ee4df93 100644 --- a/src/commands/showQuickRepoStatus.ts +++ b/src/commands/showQuickRepoStatus.ts @@ -7,7 +7,7 @@ import { CommandQuickPickItem, RepoStatusQuickPick } from '../quickPicks'; export class ShowQuickRepoStatusCommand extends ActiveEditorCachedCommand { - constructor(private git: GitService, private repoPath: string) { + constructor(private git: GitService) { super(Commands.ShowQuickRepoStatus); } @@ -17,7 +17,7 @@ export class ShowQuickRepoStatusCommand extends ActiveEditorCachedCommand { } try { - const repoPath = await this.git.getRepoPathFromUri(uri, this.repoPath); + const repoPath = await this.git.getRepoPathFromUri(uri, this.git.repoPath); if (!repoPath) return window.showWarningMessage(`Unable to show repository status`); const status = await this.git.getStatusForRepo(repoPath); diff --git a/src/constants.ts b/src/constants.ts index a94f5af..4e8d955 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -29,7 +29,6 @@ export const DocumentSchemes = { export type WorkspaceState = 'repoPath'; export const WorkspaceState = { GitLensVersion: 'gitlensVersion' as WorkspaceState, - RepoPath: 'repoPath' as WorkspaceState, SuppressGitVersionWarning: 'suppressGitVersionWarning' as WorkspaceState }; diff --git a/src/extension.ts b/src/extension.ts index 639bdfe..3477263 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -70,9 +70,7 @@ export async function activate(context: ExtensionContext) { notifyOnUnsupportedGitVersion(context, gitVersion); notifyOnNewGitLensVersion(context, gitlensVersion); - context.workspaceState.update(WorkspaceState.RepoPath, repoPath); - - const git = new GitService(context); + const git = new GitService(context, repoPath); context.subscriptions.push(git); setCommandsContext(context, git); @@ -92,31 +90,31 @@ export async function activate(context: ExtensionContext) { context.subscriptions.push(new Keyboard()); - context.subscriptions.push(new CloseUnchangedFilesCommand(git, repoPath)); - context.subscriptions.push(new OpenChangedFilesCommand(git, repoPath)); - context.subscriptions.push(new CopyMessageToClipboardCommand(git, repoPath)); - context.subscriptions.push(new CopyShaToClipboardCommand(git, repoPath)); - context.subscriptions.push(new DiffDirectoryCommand(git, repoPath)); + context.subscriptions.push(new CloseUnchangedFilesCommand(git)); + context.subscriptions.push(new OpenChangedFilesCommand(git)); + context.subscriptions.push(new CopyMessageToClipboardCommand(git)); + context.subscriptions.push(new CopyShaToClipboardCommand(git)); + context.subscriptions.push(new DiffDirectoryCommand(git)); context.subscriptions.push(new DiffLineWithPreviousCommand(git)); context.subscriptions.push(new DiffLineWithWorkingCommand(git)); context.subscriptions.push(new DiffWithBranchCommand(git)); context.subscriptions.push(new DiffWithNextCommand(git)); context.subscriptions.push(new DiffWithPreviousCommand(git)); context.subscriptions.push(new DiffWithWorkingCommand(git)); - context.subscriptions.push(new OpenCommitInRemoteCommand(git, repoPath)); - context.subscriptions.push(new OpenFileInRemoteCommand(git, repoPath)); + context.subscriptions.push(new OpenCommitInRemoteCommand(git)); + context.subscriptions.push(new OpenFileInRemoteCommand(git)); context.subscriptions.push(new OpenInRemoteCommand()); context.subscriptions.push(new ShowBlameCommand(annotationController)); context.subscriptions.push(new ToggleBlameCommand(annotationController)); context.subscriptions.push(new ShowBlameHistoryCommand(git)); context.subscriptions.push(new ShowFileHistoryCommand(git)); context.subscriptions.push(new ShowLastQuickPickCommand()); - context.subscriptions.push(new ShowQuickBranchHistoryCommand(git, repoPath)); + context.subscriptions.push(new ShowQuickBranchHistoryCommand(git)); context.subscriptions.push(new ShowQuickCurrentBranchHistoryCommand(git)); - context.subscriptions.push(new ShowQuickCommitDetailsCommand(git, repoPath)); + context.subscriptions.push(new ShowQuickCommitDetailsCommand(git)); context.subscriptions.push(new ShowQuickCommitFileDetailsCommand(git)); context.subscriptions.push(new ShowQuickFileHistoryCommand(git)); - context.subscriptions.push(new ShowQuickRepoStatusCommand(git, repoPath)); + context.subscriptions.push(new ShowQuickRepoStatusCommand(git)); context.subscriptions.push(new ToggleCodeLensCommand(git)); Telemetry.trackEvent('initialized', Objects.flatten(config, 'config', true)); diff --git a/src/gitService.ts b/src/gitService.ts index 954c0fa..75447cf 100644 --- a/src/gitService.ts +++ b/src/gitService.ts @@ -3,7 +3,7 @@ import { Iterables, Objects } from './system'; import { Disposable, Event, EventEmitter, ExtensionContext, FileSystemWatcher, languages, Location, Position, Range, TextDocument, TextEditor, Uri, workspace } from 'vscode'; import { CommandContext, setCommandContext } from './commands'; import { CodeLensVisibility, IConfig } from './configuration'; -import { DocumentSchemes, WorkspaceState } from './constants'; +import { DocumentSchemes } from './constants'; import { Git, GitBlameParser, GitBranch, GitCommit, GitLogCommit, GitLogParser, GitRemote, GitStatusFile, GitStatusParser, IGitAuthor, IGitBlame, IGitBlameLine, IGitBlameLines, IGitLog, IGitStatus } from './git/git'; import { IGitUriData, GitUri } from './git/gitUri'; import { GitCodeLensProvider } from './gitCodeLensProvider'; @@ -60,8 +60,6 @@ export class GitService extends Disposable { return this._onDidBlameFailEmitter.event; } - public repoPath: string; - private _gitCache: Map | undefined; private _remotesCache: GitRemote[]; private _cacheDisposable: Disposable | undefined; @@ -76,10 +74,9 @@ export class GitService extends Disposable { static EmptyPromise: Promise = Promise.resolve(undefined); - constructor(private context: ExtensionContext) { + constructor(private context: ExtensionContext, public repoPath: string) { super(() => this.dispose()); - this.repoPath = context.workspaceState.get(WorkspaceState.RepoPath) as string; this._uriCache = new Map(); this._onConfigurationChanged();