Skip to content

Commit

Permalink
Include upstream url and type when calling getBranches
Browse files Browse the repository at this point in the history
  • Loading branch information
ole1986 committed Feb 7, 2020
1 parent 543c0dc commit fc43c94
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
29 changes: 20 additions & 9 deletions src/adapter/repository/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,20 @@ export class Git implements IGitService {
const gitRootPath = this.repo.rootUri.fsPath;
const localBranches = this.repo.state.refs.filter(x => x.type === 0);

return localBranches.map(x => {
return await Promise.all(localBranches.map(async x => {
// tslint:disable-next-line:no-object-literal-type-assertion

let originUrl = await this.getOriginUrl(x.name);
let originType = await this.getOriginType(originUrl);

return {
gitRoot: gitRootPath,
name: x.name,
remote: originUrl,
remoteType: originType,
current: currentBranchName === x.name
} as Branch;
});
}));
}
public async getCurrentBranch(): Promise<string> {
return this.repo.state.HEAD!.name || '';
Expand Down Expand Up @@ -89,9 +95,11 @@ export class Git implements IGitService {
})
.sort((a, b) => a.name > b.name ? 1 : -1);
}
@cache('IGitService')
public async getOriginType(): Promise<GitOriginType | undefined> {
const url = await this.getOriginUrl();

public async getOriginType(url?: string): Promise<GitOriginType | undefined> {
if (!url) {
url = await this.getOriginUrl();
}

if (url.indexOf('github.com') > 0) {
return GitOriginType.github;
Expand All @@ -102,10 +110,13 @@ export class Git implements IGitService {
}
return undefined;
}
@cache('IGitService')
public async getOriginUrl(): Promise<string> {
const currentBranchName = await this.getCurrentBranch();
const branch = await this.repo.getBranch(currentBranchName);

public async getOriginUrl(branchName?: string): Promise<string> {
if (!branchName) {
branchName = await this.getCurrentBranch();
}

const branch = await this.repo.getBranch(branchName);

if (branch.upstream) {
const remoteIndex = this.repo.state.remotes.findIndex(x => x.name === branch.upstream!.remote);
Expand Down
2 changes: 2 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ export type Remote = {
export type Branch = {
gitRoot: string;
name: string;
remote: string;
remoteType: GitOriginType | undefined;
current: boolean;
};

Expand Down

0 comments on commit fc43c94

Please sign in to comment.