mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-27 03:54:24 +01:00
Merge commit 'refs/pull/45341/head' of github.com:Microsoft/vscode into pr/45341
This commit is contained in:
@@ -1331,7 +1331,7 @@ export class CommandCenter {
|
||||
return;
|
||||
}
|
||||
|
||||
const remotePicks = remotes.map(r => ({ label: r.name, description: r.url }));
|
||||
const remotePicks = remotes.filter(r => r.fetchUrl !== undefined).map(r => ({ label: r.name, description: r.fetchUrl! }));
|
||||
const placeHolder = localize('pick remote pull repo', "Pick a remote to pull the branch from");
|
||||
const remotePick = await window.showQuickPick(remotePicks, { placeHolder });
|
||||
|
||||
@@ -1438,7 +1438,7 @@ export class CommandCenter {
|
||||
}
|
||||
|
||||
const branchName = repository.HEAD.name;
|
||||
const picks = remotes.map(r => ({ label: r.name, description: r.url }));
|
||||
const picks = remotes.filter(r => r.pushUrl !== undefined).map(r => ({ label: r.name, description: r.pushUrl! }));
|
||||
const placeHolder = localize('pick remote', "Pick a remote to publish the branch '{0}' to:", branchName);
|
||||
const pick = await window.showQuickPick(picks, { placeHolder });
|
||||
|
||||
|
||||
@@ -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> {
|
||||
|
||||
@@ -789,23 +789,24 @@ export class Repository implements Disposable {
|
||||
}
|
||||
|
||||
private async _sync(head: Branch, rebase: boolean): Promise<void> {
|
||||
let remote: string | undefined;
|
||||
let remoteName: string | undefined;
|
||||
let pullBranch: string | undefined;
|
||||
let pushBranch: string | undefined;
|
||||
|
||||
if (head.name && head.upstream) {
|
||||
remote = head.upstream.remote;
|
||||
remoteName = head.upstream.remote;
|
||||
pullBranch = `${head.upstream.name}`;
|
||||
pushBranch = `${head.name}:${head.upstream.name}`;
|
||||
}
|
||||
|
||||
await this.run(Operation.Sync, async () => {
|
||||
await this.repository.pull(rebase, remote, pullBranch);
|
||||
await this.repository.pull(rebase, remoteName, pullBranch);
|
||||
|
||||
const shouldPush = this.HEAD && typeof this.HEAD.ahead === 'number' ? this.HEAD.ahead > 0 : true;
|
||||
const remote = this.remotes.find(r => r.name === remoteName);
|
||||
const shouldPush = this.HEAD && (typeof this.HEAD.ahead === 'number' ? this.HEAD.ahead > 0 : true) && (!remote || remote.canPush);
|
||||
|
||||
if (shouldPush) {
|
||||
await this.repository.push(remote, pushBranch);
|
||||
await this.repository.push(remoteName, pushBranch);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -1150,6 +1151,13 @@ export class Repository implements Disposable {
|
||||
return '';
|
||||
}
|
||||
|
||||
const remoteName = this.HEAD && this.HEAD.remote || this.HEAD.upstream.remote;
|
||||
const remote = this.remotes.find(r => r.name === remoteName);
|
||||
|
||||
if (remote && !remote.canPush) {
|
||||
return `${this.HEAD.behind}↓`;
|
||||
}
|
||||
|
||||
return `${this.HEAD.behind}↓ ${this.HEAD.ahead}↑`;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user