mirror of
https://github.com/ckaczor/vscode-gitlens.git
synced 2026-01-14 01:25:43 -05:00
Stops Git from leaking out of GitService
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
'use strict';
|
||||
import { commands, InputBoxOptions, TextEditor, Uri, window } from 'vscode';
|
||||
import { ActiveEditorCachedCommand, Commands } from './common';
|
||||
import { Git, GitRepoSearchBy, GitService, GitUri } from '../gitService';
|
||||
import { GitRepoSearchBy, GitService, GitUri } from '../gitService';
|
||||
import { Logger } from '../logger';
|
||||
import { CommandQuickPickItem, CommitsQuickPick } from '../quickPicks';
|
||||
|
||||
@@ -39,7 +39,7 @@ export class ShowCommitSearchCommand extends ActiveEditorCachedCommand {
|
||||
searchBy = searchByMap.get(match[1]);
|
||||
search = search.substring((search[1] === ' ') ? 2 : 1);
|
||||
}
|
||||
else if (Git.isSha(search)) {
|
||||
else if (GitService.isSha(search)) {
|
||||
searchBy = GitRepoSearchBy.Sha;
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -20,7 +20,7 @@ import { Keyboard } from './commands';
|
||||
import { IConfig } from './configuration';
|
||||
import { ApplicationInsightsKey, BuiltInCommands, ExtensionId, WorkspaceState } from './constants';
|
||||
import { GitContentProvider } from './gitContentProvider';
|
||||
import { Git, GitContextTracker, GitService } from './gitService';
|
||||
import { GitContextTracker, GitService } from './gitService';
|
||||
import { GitRevisionCodeLensProvider } from './gitRevisionCodeLensProvider';
|
||||
import { Logger } from './logger';
|
||||
import { Telemetry } from './telemetry';
|
||||
@@ -40,7 +40,7 @@ export async function activate(context: ExtensionContext) {
|
||||
const gitPath = config.advanced.git;
|
||||
|
||||
try {
|
||||
await Git.getGitPath(gitPath);
|
||||
await GitService.getGitPath(gitPath);
|
||||
}
|
||||
catch (ex) {
|
||||
Logger.error(ex, 'Extension.activate');
|
||||
@@ -51,9 +51,9 @@ export async function activate(context: ExtensionContext) {
|
||||
return;
|
||||
}
|
||||
|
||||
const repoPath = await Git.getRepoPath(rootPath);
|
||||
const repoPath = await GitService.getRepoPath(rootPath);
|
||||
|
||||
const gitVersion = Git.gitInfo().version;
|
||||
const gitVersion = GitService.getGitVersion();
|
||||
Logger.log(`Git version: ${gitVersion}`);
|
||||
|
||||
const telemetryContext: { [id: string]: any } = Object.create(null);
|
||||
@@ -146,7 +146,7 @@ async function notifyOnUnsupportedGitVersion(context: ExtensionContext, version:
|
||||
if (context.globalState.get(WorkspaceState.SuppressGitVersionWarning, false)) return;
|
||||
|
||||
// If git is less than v2.2.0
|
||||
if (!Git.validateVersion(2, 2)) {
|
||||
if (!GitService.validateGitVersion(2, 2)) {
|
||||
const result = await window.showErrorMessage(`GitLens requires a newer version of Git (>= 2.2.0) than is currently installed (${version}). Please install a more recent version of Git.`, `Don't Show Again`);
|
||||
if (result === `Don't Show Again`) {
|
||||
context.globalState.update(WorkspaceState.SuppressGitVersionWarning, true);
|
||||
|
||||
@@ -6,6 +6,7 @@ import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
import * as tmp from 'tmp';
|
||||
|
||||
export { IGit };
|
||||
export * from './models/models';
|
||||
export * from './parsers/blameParser';
|
||||
export * from './parsers/logParser';
|
||||
@@ -47,7 +48,7 @@ export class Git {
|
||||
return git;
|
||||
}
|
||||
|
||||
static async getGitPath(gitPath?: string) {
|
||||
static async getGitPath(gitPath?: string): Promise<IGit> {
|
||||
git = await findGitPath(gitPath);
|
||||
Logger.log(`Git found: ${git.version} @ ${git.path === 'git' ? 'PATH' : git.path}`);
|
||||
return git;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
'use strict';
|
||||
import { Uri } from 'vscode';
|
||||
import { DocumentSchemes } from '../constants';
|
||||
import { Git, GitCommit, GitService, IGitStatusFile } from '../gitService';
|
||||
import { GitCommit, GitService, IGitStatusFile } from '../gitService';
|
||||
import * as path from 'path';
|
||||
|
||||
export class GitUri extends Uri {
|
||||
@@ -30,7 +30,7 @@ export class GitUri extends Uri {
|
||||
base._fsPath = path.resolve(data.repoPath, data.originalFileName || data.fileName);
|
||||
|
||||
this.offset = (data.decoration && data.decoration.split('\n').length) || 0;
|
||||
if (!Git.isUncommitted(data.sha)) {
|
||||
if (!GitService.isUncommitted(data.sha)) {
|
||||
this.sha = data.sha;
|
||||
this.repoPath = data.repoPath;
|
||||
}
|
||||
@@ -43,7 +43,7 @@ export class GitUri extends Uri {
|
||||
const commit = commitOrRepoPath;
|
||||
base._fsPath = path.resolve(commit.repoPath, commit.originalFileName || commit.fileName);
|
||||
|
||||
if (!Git.isUncommitted(commit.sha)) {
|
||||
if (!GitService.isUncommitted(commit.sha)) {
|
||||
this.sha = commit.sha;
|
||||
this.repoPath = commit.repoPath;
|
||||
}
|
||||
@@ -64,7 +64,7 @@ export class GitUri extends Uri {
|
||||
if (this.repoPath) {
|
||||
directory = path.relative(this.repoPath, directory);
|
||||
}
|
||||
directory = Git.normalizePath(directory);
|
||||
directory = GitService.normalizePath(directory);
|
||||
|
||||
return (!directory || directory === '.')
|
||||
? path.basename(this.fsPath)
|
||||
@@ -72,7 +72,7 @@ export class GitUri extends Uri {
|
||||
}
|
||||
|
||||
getRelativePath(): string {
|
||||
return Git.normalizePath(path.relative(this.repoPath, this.fsPath));
|
||||
return GitService.normalizePath(path.relative(this.repoPath, this.fsPath));
|
||||
}
|
||||
|
||||
static async fromUri(uri: Uri, git: GitService) {
|
||||
|
||||
@@ -4,7 +4,7 @@ import { Disposable, Event, EventEmitter, ExtensionContext, FileSystemWatcher, l
|
||||
import { CommandContext, setCommandContext } from './commands';
|
||||
import { CodeLensVisibility, IConfig } from './configuration';
|
||||
import { DocumentSchemes } from './constants';
|
||||
import { Git, GitBlameParser, GitBranch, GitCommit, GitLogCommit, GitLogParser, GitRemote, GitStashParser, GitStatusFile, GitStatusParser, IGitAuthor, IGitBlame, IGitBlameLine, IGitBlameLines, IGitLog, IGitStash, IGitStatus } from './git/git';
|
||||
import { Git, GitBlameParser, GitBranch, GitCommit, GitLogCommit, GitLogParser, GitRemote, GitStashParser, GitStatusFile, GitStatusParser, IGit, IGitAuthor, IGitBlame, IGitBlameLine, IGitBlameLines, IGitLog, IGitStash, IGitStatus } from './git/git';
|
||||
import { IGitUriData, GitUri } from './git/gitUri';
|
||||
import { GitCodeLensProvider } from './gitCodeLensProvider';
|
||||
import { Logger } from './logger';
|
||||
@@ -14,7 +14,8 @@ import * as moment from 'moment';
|
||||
import * as path from 'path';
|
||||
|
||||
export { GitUri };
|
||||
export * from './git/git';
|
||||
export * from './git/models/models';
|
||||
export { getNameFromRemoteOpenType, RemoteOpenType } from './git/remotes/provider';
|
||||
export * from './git/gitContextTracker';
|
||||
|
||||
class UriCacheEntry {
|
||||
@@ -840,6 +841,18 @@ export class GitService extends Disposable {
|
||||
this._codeLensProviderDisposable = languages.registerCodeLensProvider(GitCodeLensProvider.selector, new GitCodeLensProvider(this.context, this));
|
||||
}
|
||||
|
||||
static getGitPath(gitPath?: string): Promise<IGit> {
|
||||
return Git.getGitPath(gitPath);
|
||||
}
|
||||
|
||||
static getGitVersion(): string {
|
||||
return Git.gitInfo().version;
|
||||
}
|
||||
|
||||
static getRepoPath(cwd: string): Promise<string> {
|
||||
return Git.getRepoPath(cwd);
|
||||
}
|
||||
|
||||
static fromGitContentUri(uri: Uri): IGitUriData {
|
||||
if (uri.scheme !== DocumentSchemes.GitLensGit) throw new Error(`fromGitUri(uri=${uri}) invalid scheme`);
|
||||
return GitService._fromGitContentUri<IGitUriData>(uri);
|
||||
@@ -849,10 +862,18 @@ export class GitService extends Disposable {
|
||||
return JSON.parse(uri.query) as T;
|
||||
}
|
||||
|
||||
static isUncommitted(sha: string) {
|
||||
static isSha(sha: string): boolean {
|
||||
return Git.isSha(sha);
|
||||
}
|
||||
|
||||
static isUncommitted(sha: string): boolean {
|
||||
return Git.isUncommitted(sha);
|
||||
}
|
||||
|
||||
static normalizePath(fileName: string, repoPath?: string): string {
|
||||
return Git.normalizePath(fileName, repoPath);
|
||||
}
|
||||
|
||||
static toGitContentUri(sha: string, shortSha: string, fileName: string, repoPath: string, originalFileName: string): Uri;
|
||||
static toGitContentUri(commit: GitCommit): Uri;
|
||||
static toGitContentUri(shaOrcommit: string | GitCommit, shortSha?: string, fileName?: string, repoPath?: string, originalFileName?: string): Uri {
|
||||
@@ -904,4 +925,9 @@ export class GitService extends Disposable {
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
static validateGitVersion(major: number, minor: number): boolean {
|
||||
const [gitMajor, gitMinor] = this.getGitVersion().split('.');
|
||||
return (parseInt(gitMajor, 10) >= major && parseInt(gitMinor, 10) >= minor);
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,7 @@ import { Arrays, Iterables } from '../system';
|
||||
import { QuickPickItem, QuickPickOptions, Uri, window } from 'vscode';
|
||||
import { Commands, Keyboard, KeyNoopCommand } from '../commands';
|
||||
import { CommandQuickPickItem, getQuickPickIgnoreFocusOut, KeyCommandQuickPickItem, OpenFileCommandQuickPickItem, OpenFilesCommandQuickPickItem } from './common';
|
||||
import { getGitStatusIcon, Git, GitCommit, GitLogCommit, GitService, GitStashCommit, GitStatusFileStatus, GitUri, IGitLog, IGitStatusFile } from '../gitService';
|
||||
import { getGitStatusIcon, GitCommit, GitLogCommit, GitService, GitStashCommit, GitStatusFileStatus, GitUri, IGitLog, IGitStatusFile } from '../gitService';
|
||||
import { OpenRemotesCommandQuickPickItem } from './remotes';
|
||||
import * as moment from 'moment';
|
||||
import * as path from 'path';
|
||||
@@ -19,7 +19,7 @@ export class CommitWithFileStatusQuickPickItem extends OpenFileCommandQuickPickI
|
||||
constructor(commit: GitCommit, status: IGitStatusFile) {
|
||||
const icon = getGitStatusIcon(status.status);
|
||||
|
||||
let directory = Git.normalizePath(path.dirname(status.fileName));
|
||||
let directory = GitService.normalizePath(path.dirname(status.fileName));
|
||||
if (!directory || directory === '.') {
|
||||
directory = undefined;
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ import { Iterables } from '../system';
|
||||
import { QuickPickItem, QuickPickOptions, Uri, window } from 'vscode';
|
||||
import { Commands, Keyboard } from '../commands';
|
||||
import { CommandQuickPickItem, getQuickPickIgnoreFocusOut, OpenFileCommandQuickPickItem } from './common';
|
||||
import { Git, GitStatusFile, GitUri, IGitStatus } from '../gitService';
|
||||
import { GitService, GitStatusFile, GitUri, IGitStatus } from '../gitService';
|
||||
import * as path from 'path';
|
||||
|
||||
export class OpenStatusFileCommandQuickPickItem extends OpenFileCommandQuickPickItem {
|
||||
@@ -11,7 +11,7 @@ export class OpenStatusFileCommandQuickPickItem extends OpenFileCommandQuickPick
|
||||
constructor(status: GitStatusFile, item?: QuickPickItem) {
|
||||
const icon = status.getIcon();
|
||||
|
||||
let directory = Git.normalizePath(path.dirname(status.fileName));
|
||||
let directory = GitService.normalizePath(path.dirname(status.fileName));
|
||||
if (!directory || directory === '.') {
|
||||
directory = undefined;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user