From 1377fb6eb715caf8d35ddffcba354dae734e6ee3 Mon Sep 17 00:00:00 2001 From: Phil Kunz Date: Thu, 20 Jun 2019 14:19:54 +0200 Subject: [PATCH] fix(core): update --- ts/smartgit.classes.gitrepo.ts | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/ts/smartgit.classes.gitrepo.ts b/ts/smartgit.classes.gitrepo.ts index ed39172..cb0ca83 100644 --- a/ts/smartgit.classes.gitrepo.ts +++ b/ts/smartgit.classes.gitrepo.ts @@ -42,13 +42,27 @@ export class GitRepo { public async listRemotes(): Promise { return this.nodegitRepo.getRemotes(); } + public async ensureRemote(remoteNameArg: string, remoteUrlArg: string): Promise { + const existingUrl = await this.getUrlForRemote(remoteNameArg); + if (existingUrl === remoteUrlArg) { + return; + } + if (existingUrl) { + await plugins.nodegit.Remote.delete(this.nodegitRepo, remoteNameArg); + } + await plugins.nodegit.Remote.create(this.nodegitRepo, remoteNameArg, remoteUrlArg); + } /** * gets the url for a specific remote */ - public async getUrlForRemote(remoteName: string) { + public async getUrlForRemote(remoteName: string): Promise { const ngRemote = await this.nodegitRepo.getRemote(remoteName); - return ngRemote.url; + if (ngRemote) { + return ngRemote.url(); + } else { + return null; + } } public async pushBranchToRemote(branchName: string, remoteName: string) {