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

git: 💄 no_push feature

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