提交 c1d71724 编写于 作者: J Joao Moreno

fix npe in non git workspaces

上级 c70b4866
......@@ -8,7 +8,7 @@ import { TPromise } from 'vs/base/common/winjs.base';
import { Server } from 'vs/base/node/service.cp';
import objects = require('vs/base/common/objects');
import uri from 'vs/base/common/uri';
import { IRawGitService } from 'vs/workbench/parts/git/common/git';
import { IRawGitService, GitErrorCodes } from 'vs/workbench/parts/git/common/git';
import gitlib = require('vs/workbench/parts/git/node/git.lib');
import { RawGitService, DelayedRawGitService } from 'vs/workbench/parts/git/node/rawGitService';
import { join, dirname, normalize } from 'path';
......@@ -23,6 +23,7 @@ class IPCRawGitService extends DelayedRawGitService {
} else {
const gitRootPath = uri.parse(require.toUrl('vs/workbench/parts/git/electron-main')).fsPath;
const bootstrapPath = `${ uri.parse(require.toUrl('bootstrap')).fsPath }.js`;
workspaceRoot = normalize(workspaceRoot);
const env = objects.assign({}, process.env, {
GIT_ASKPASS: join(gitRootPath, 'askpass.sh'),
......@@ -38,8 +39,15 @@ class IPCRawGitService extends DelayedRawGitService {
env: env
});
const repo = git.open(normalize(workspaceRoot));
const repo = git.open(workspaceRoot);
const promise = repo.getRoot()
.then<string>(null, (err: gitlib.GitError) => {
if (err instanceof gitlib.GitError && err.gitErrorCode === GitErrorCodes.NotAGitRepository) {
return workspaceRoot;
}
return TPromise.wrapError(err);
})
.then(root => realpath(root))
.then(root => git.open(root))
.then(repo => new RawGitService(repo));
......
......@@ -186,6 +186,8 @@ export class Git {
if (/Authentication failed/.test(result.stderr)) {
gitErrorCode = GitErrorCodes.AuthenticationFailed;
} else if (/Not a git repository/.test(result.stderr)) {
gitErrorCode = GitErrorCodes.NotAGitRepository;
} else if (/bad config file/.test(result.stderr)) {
gitErrorCode = GitErrorCodes.BadConfigFile;
} else if (/cannot make pipe for command substitution|cannot create standard input pipe/.test(result.stderr)) {
......@@ -496,8 +498,6 @@ export class Repository {
return this.run(['fetch']).then(null, (err: GitError) => {
if (/No remote repository specified\./.test(err.stderr)) {
err.gitErrorCode = GitErrorCodes.NoRemoteRepositorySpecified;
} else if (/Not a git repository/.test(err.stderr)) {
err.gitErrorCode = GitErrorCodes.NotAGitRepository;
} else if (/Could not read from remote repository/.test(err.stderr)) {
err.gitErrorCode = GitErrorCodes.RemoteConnectionError;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册