Browse Source

Fixes issues with detached HEAD

main
Eric Amodio 7 years ago
parent
commit
88582c54c9
2 changed files with 5 additions and 1 deletions
  1. +3
    -1
      src/git/git.ts
  2. +2
    -0
      src/gitService.ts

+ 3
- 1
src/git/git.ts View File

@ -394,7 +394,7 @@ export class Git {
return gitCommand({ cwd: repoPath }, 'remote', 'get-url', remote);
}
static async revparse_currentBranch(repoPath: string) {
static async revparse_currentBranch(repoPath: string): Promise<string | undefined> {
const params = [`rev-parse`, `--abbrev-ref`, `--symbolic-full-name`, `@`, `@{u}`];
const opts = { cwd: repoPath, willHandleErrors: true } as GitCommandOptions;
@ -403,6 +403,8 @@ 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];
}

+ 2
- 0
src/gitService.ts View File

@ -548,6 +548,8 @@ export class GitService extends Disposable {
Logger.log(`getBranch('${repoPath}')`);
const data = await Git.revparse_currentBranch(repoPath);
if (data === undefined) return undefined;
const branch = data.split('\n');
return new GitBranch(repoPath, branch[0], true, branch[1]);
}

Loading…
Cancel
Save