Only prune forked remotes without local branches

Co-Authored-By: Markus Olsson <634063+niik@users.noreply.github.com>
This commit is contained in:
Sergio Padrino 2020-12-18 13:21:43 +01:00
parent 8518282f31
commit 1bb8731d85

View file

@ -1642,16 +1642,17 @@ export class GitStore extends BaseStore {
public async pruneForkedRemotes(openPRs: ReadonlyArray<PullRequest>) {
const remotes = await getRemotes(this.repository)
const prRemotes = new Set<string>()
for (const pr of openPRs) {
if (pr.head.gitHubRepository.cloneURL !== null) {
prRemotes.add(pr.head.gitHubRepository.cloneURL)
}
}
const prRemoteUrls = new Set(
openPRs.map(pr => pr.head.gitHubRepository.cloneURL)
)
const branchRemotes = new Set(this.allBranches.map(branch => branch.remote))
for (const r of remotes) {
if (r.name.startsWith(ForkedRemotePrefix) && !prRemotes.has(r.url)) {
if (
r.name.startsWith(ForkedRemotePrefix) &&
!prRemoteUrls.has(r.url) &&
!branchRemotes.has(r.name)
) {
await removeRemote(this.repository, r.name)
}
}