Skip to content

Commit dbdc4cc

Browse files
committed
Deals with newly initialized repo
1 parent 0021510 commit dbdc4cc

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

src/git/git.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ const GitWarnings = [
3434
/does not have any commits/,
3535
/Path \'.*?\' does not exist in/,
3636
/Path \'.*?\' exists on disk, but not in/,
37-
/no upstream configured for branch/
37+
/no upstream configured for branch/,
38+
/ambiguous argument '.*?': unknown revision or path not in the working tree/
3839
];
3940

4041
interface GitCommandOptions {
@@ -436,10 +437,19 @@ export class Git {
436437
return data;
437438
}
438439
catch (ex) {
439-
if (/HEAD does not point to a branch/.test(ex && ex.toString())) return undefined;
440-
441-
if (/no upstream configured for branch/.test(ex && ex.toString())) {
442-
return ex.message.split('\n')[0];
440+
const msg = ex && ex.toString();
441+
if (/HEAD does not point to a branch/.test(msg)) return undefined;
442+
if (/no upstream configured for branch/.test(msg)) return ex.message.split('\n')[0];
443+
444+
if (/ambiguous argument '.*?': unknown revision or path not in the working tree/.test(msg)) {
445+
try {
446+
const params = [`symbolic-ref`, `-q`, `--short`, `HEAD`];
447+
const data = await gitCommand(opts, ...params);
448+
return data;
449+
}
450+
catch {
451+
return undefined;
452+
}
443453
}
444454

445455
return gitCommandDefaultErrorHandler(ex, opts, ...params);

src/gitService.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -692,6 +692,12 @@ export class GitService extends Disposable {
692692
Logger.log(`getBranches('${repoPath}')`);
693693

694694
const data = await Git.branch(repoPath, { all: true });
695+
// If we don't get any data, assume the repo doesn't have any commits yet so check if we have a current branch
696+
if (data === '') {
697+
const current = await this.getBranch(repoPath);
698+
return current !== undefined ? [current] : [];
699+
}
700+
695701
return GitBranchParser.parse(data, repoPath) || [];
696702
}
697703

0 commit comments

Comments
 (0)