diff --git a/extensions/git/src/commands.ts b/extensions/git/src/commands.ts index 7d545c427b8d9a578ea5fd50b775c29ee37ebaf1..6922820b37d12d21231a4808659bcc9e410f4c4d 100644 --- a/extensions/git/src/commands.ts +++ b/extensions/git/src/commands.ts @@ -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('confirmSync') === true; + const shouldPrompt = !isReadonly && config.get('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); diff --git a/extensions/git/src/git.ts b/extensions/git/src/git.ts index 1b6c6c3721083491612e80f8e725efdc4f1305e1..71a8cbc901401be952c9b4425ea6553797e12e08 100644 --- a/extensions/git/src/git.ts +++ b/extensions/git/src/git.ts @@ -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 { 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; diff --git a/extensions/git/src/repository.ts b/extensions/git/src/repository.ts index 6ce0792acd1cfae6ef51538326475eb049bad78f..6df487e1f4bf602ee7fd1ea05f06d8f187c0b72f 100644 --- a/extensions/git/src/repository.ts +++ b/extensions/git/src/repository.ts @@ -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}↓`; }