Skip to content

Commit 703fc18

Browse files
authored
fix: handle missing tracking branch (#483)
1 parent ec3826b commit 703fc18

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

src/isomorphicGit.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -511,8 +511,13 @@ export class IsomorphicGit extends GitManager {
511511
const status = await this.branchInfo();
512512
const trackingBranch = status.tracking;
513513
const currentBranch = status.current;
514-
const localCommit = await this.resolveRef(currentBranch!);
515-
const upstreamCommit = await this.resolveRef(trackingBranch!);
514+
515+
if (trackingBranch == null || currentBranch == null) {
516+
return 0;
517+
}
518+
519+
const localCommit = await this.resolveRef(currentBranch);
520+
const upstreamCommit = await this.resolveRef(trackingBranch);
516521

517522
const changedFiles = await this.getFileChangesCount(
518523
localCommit,

src/simpleGit.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -368,8 +368,13 @@ export class SimpleGit extends GitManager {
368368

369369
async getUnpushedCommits(): Promise<number> {
370370
const status = await this.git.status();
371-
const trackingBranch = status.tracking!;
372-
const currentBranch = status.current!;
371+
const trackingBranch = status.tracking;
372+
const currentBranch = status.current;
373+
374+
if (trackingBranch == null || currentBranch == null) {
375+
return 0;
376+
}
377+
373378
const remoteChangedFiles = (
374379
await this.git.diffSummary(
375380
[currentBranch, trackingBranch, "--"],

0 commit comments

Comments
 (0)