提交 c693ba29 编写于 作者: J Joao Moreno

git: 💄 no_push feature

上级 fb29dd07
......@@ -1456,8 +1456,12 @@ export class CommandCenter {
return;
}
const remoteName = HEAD.remote || HEAD.upstream.remote;
const remote = repository.remotes.find(r => r.name === remoteName);
const isReadonly = remote && remote.isReadOnly;
const config = workspace.getConfiguration('git');
const shouldPrompt = config.get<boolean>('confirmSync') === true;
const shouldPrompt = !isReadonly && config.get<boolean>('confirmSync') === true;
if (shouldPrompt) {
const message = localize('sync is unpredictable', "This action will push and pull commits to and from '{0}/{1}'.", HEAD.upstream.remote, HEAD.upstream.name);
......
......@@ -35,7 +35,7 @@ export interface Remote {
name: string;
fetchUrl?: string;
pushUrl?: string;
canPush: boolean;
isReadOnly: boolean;
}
export interface Stash {
......@@ -1228,34 +1228,31 @@ export class Repository {
async getRemotes(): Promise<Remote[]> {
const result = await this.run(['remote', '--verbose']);
const remotes: Remote[] = [];
const lines = result.stdout.trim().split('\n').filter(l => !!l);
const remotes: Remote[] = [];
for (const line of lines) {
const parts = line.split(/\s/);
let remote = remotes.find(r => r.name === parts[0]);
const [name, url, type] = parts;
let remote = remotes.find(r => r.name === name);
if (!remote) {
remote = { name: parts[0], canPush: true };
remote = { name, isReadOnly: false };
remotes.push(remote);
}
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;
}
if (/fetch/i.test(type)) {
remote.fetchUrl = url;
} else if (/push/i.test(type)) {
remote.pushUrl = url;
} else {
remote.fetchUrl = url;
remote.pushUrl = url;
}
// https://github.com/Microsoft/vscode/issues/45271
remote.canPush = remote.pushUrl !== undefined && remote.pushUrl !== 'no_push';
remote.isReadOnly = remote.pushUrl === undefined || remote.pushUrl === 'no_push';
}
return remotes;
......
......@@ -803,7 +803,12 @@ export class Repository implements Disposable {
await this.repository.pull(rebase, remoteName, pullBranch);
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 (remote && remote.isReadOnly) {
return;
}
const shouldPush = this.HEAD && (typeof this.HEAD.ahead === 'number' ? this.HEAD.ahead > 0 : true);
if (shouldPush) {
await this.repository.push(remoteName, pushBranch);
......@@ -1154,7 +1159,7 @@ export class Repository implements Disposable {
const remoteName = this.HEAD && this.HEAD.remote || this.HEAD.upstream.remote;
const remote = this.remotes.find(r => r.name === remoteName);
if (remote && !remote.canPush) {
if (remote && remote.isReadOnly) {
return `${this.HEAD.behind}↓`;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册