This commit is contained in:
Joao Moreno
2018-03-02 17:31:37 +01:00
parent e33436acb1
commit c889303366
3 changed files with 63 additions and 28 deletions

View File

@@ -53,8 +53,13 @@ export interface Ref {
remote?: string;
}
export interface UpstreamRef {
remote: string;
name: string;
}
export interface Branch extends Ref {
upstream?: string;
upstream?: UpstreamRef;
ahead?: number;
behind?: number;
}
@@ -1218,10 +1223,16 @@ export class Repository {
const commit = result.stdout.trim();
try {
const res2 = await this.run(['rev-parse', '--symbolic-full-name', '--abbrev-ref', name + '@{u}']);
const upstream = res2.stdout.trim();
const res2 = await this.run(['rev-parse', '--symbolic-full-name', name + '@{u}']);
const fullUpstream = res2.stdout.trim();
const match = /^refs\/remotes\/([^/]+)\/(.+)$/.exec(fullUpstream);
const res3 = await this.run(['rev-list', '--left-right', name + '...' + upstream]);
if (!match) {
throw new Error(`Could not parse upstream branch: ${fullUpstream}`);
}
const upstream = { remote: match[1], name: match[2] };
const res3 = await this.run(['rev-list', '--left-right', name + '...' + fullUpstream]);
let ahead = 0, behind = 0;
let i = 0;