Browse Source

Deals with newly initialized repo

main
Eric Amodio 7 years ago
parent
commit
dbdc4ccfac
2 changed files with 21 additions and 5 deletions
  1. +15
    -5
      src/git/git.ts
  2. +6
    -0
      src/gitService.ts

+ 15
- 5
src/git/git.ts View File

@ -34,7 +34,8 @@ const GitWarnings = [
/does not have any commits/,
/Path \'.*?\' does not exist in/,
/Path \'.*?\' exists on disk, but not in/,
/no upstream configured for branch/
/no upstream configured for branch/,
/ambiguous argument '.*?': unknown revision or path not in the working tree/
];
interface GitCommandOptions {
@ -436,10 +437,19 @@ export class Git {
return data;
}
catch (ex) {
if (/HEAD does not point to a branch/.test(ex && ex.toString())) return undefined;
if (/no upstream configured for branch/.test(ex && ex.toString())) {
return ex.message.split('\n')[0];
const msg = ex && ex.toString();
if (/HEAD does not point to a branch/.test(msg)) return undefined;
if (/no upstream configured for branch/.test(msg)) return ex.message.split('\n')[0];
if (/ambiguous argument '.*?': unknown revision or path not in the working tree/.test(msg)) {
try {
const params = [`symbolic-ref`, `-q`, `--short`, `HEAD`];
const data = await gitCommand(opts, ...params);
return data;
}
catch {
return undefined;
}
}
return gitCommandDefaultErrorHandler(ex, opts, ...params);

+ 6
- 0
src/gitService.ts View File

@ -692,6 +692,12 @@ export class GitService extends Disposable {
Logger.log(`getBranches('${repoPath}')`);
const data = await Git.branch(repoPath, { all: true });
// If we don't get any data, assume the repo doesn't have any commits yet so check if we have a current branch
if (data === '') {
const current = await this.getBranch(repoPath);
return current !== undefined ? [current] : [];
}
return GitBranchParser.parse(data, repoPath) || [];
}

Loading…
Cancel
Save