Merge commit 'refs/pull/45341/head' of github.com:Microsoft/vscode into pr/45341

This commit is contained in:
Joao Moreno
2018-06-04 16:33:06 +02:00
3 changed files with 49 additions and 16 deletions

View File

@@ -13,7 +13,7 @@ import * as which from 'which';
import { EventEmitter } from 'events';
import iconv = require('iconv-lite');
import * as filetype from 'file-type';
import { assign, uniqBy, groupBy, denodeify, IDisposable, toDisposable, dispose, mkdirp, readBytes, detectUnicodeEncoding, Encoding, onceEvent } from './util';
import { assign, groupBy, denodeify, IDisposable, toDisposable, dispose, mkdirp, readBytes, detectUnicodeEncoding, Encoding, onceEvent } from './util';
import { CancellationToken } from 'vscode';
import { detectEncoding } from './encoding';
@@ -33,7 +33,9 @@ export interface IFileStatus {
export interface Remote {
name: string;
url: string;
fetchUrl?: string;
pushUrl?: string;
canPush: boolean;
}
export interface Stash {
@@ -1226,14 +1228,37 @@ export class Repository {
async getRemotes(): Promise<Remote[]> {
const result = await this.run(['remote', '--verbose']);
const regex = /^([^\s]+)\s+([^\s]+)\s/;
const rawRemotes = result.stdout.trim().split('\n')
.filter(b => !!b)
.map(line => regex.exec(line) as RegExpExecArray)
.filter(g => !!g)
.map((groups: RegExpExecArray) => ({ name: groups[1], url: groups[2] }));
const remotes: Remote[] = [];
const lines = result.stdout.trim().split('\n').filter(l => !!l);
for (const line of lines) {
const parts = line.split(/\s/);
let remote = remotes.find(r => r.name === parts[0]);
if (!remote) {
remote = { name: parts[0], canPush: true };
remotes.push(remote);
}
return uniqBy(rawRemotes, remote => remote.name);
switch (parts[2]) {
case '(fetch)': {
remote.fetchUrl = parts[1];
break;
}
case '(push)': {
remote.pushUrl = parts[1];
break;
}
default: {
remote.fetchUrl = parts[1];
remote.pushUrl = parts[1];
break;
}
}
// https://github.com/Microsoft/vscode/issues/45271
remote.canPush = remote.pushUrl !== undefined && remote.pushUrl !== 'no_push';
}
return remotes;
}
async getBranch(name: string): Promise<Branch> {