Skip to content

Commit

Permalink
fix npe in non git workspaces
Browse files Browse the repository at this point in the history
  • Loading branch information
joaomoreno committed Dec 1, 2015
1 parent c70b486 commit c1d7172
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
12 changes: 10 additions & 2 deletions src/vs/workbench/parts/git/electron-browser/gitApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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'),
Expand All @@ -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));
Expand Down
4 changes: 2 additions & 2 deletions src/vs/workbench/parts/git/node/git.lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit c1d7172

Please sign in to comment.