diff --git a/app/src/lib/git/branch.ts b/app/src/lib/git/branch.ts index c9ab3ed6174..936c792191a 100644 --- a/app/src/lib/git/branch.ts +++ b/app/src/lib/git/branch.ts @@ -76,7 +76,6 @@ export async function deleteRemoteBranch( remoteName: string, remoteBranchName: string ): Promise { - const networkArguments = await gitNetworkArguments(repository, account) const remoteUrl = (await getRemoteURL(repository, remoteName).catch(err => { // If we can't get the URL then it's very unlikely Git will be able to @@ -86,7 +85,12 @@ export async function deleteRemoteBranch( return null })) || getFallbackUrlForProxyResolve(account, repository) - const args = [...networkArguments, 'push', remoteName, `:${remoteBranchName}`] + const args = [ + ...gitNetworkArguments(), + 'push', + remoteName, + `:${remoteBranchName}`, + ] // If the user is not authenticated, the push is going to fail // Let this propagate and leave it to the caller to handle diff --git a/app/src/lib/git/checkout.ts b/app/src/lib/git/checkout.ts index 7831717022c..5ffbdc46f3c 100644 --- a/app/src/lib/git/checkout.ts +++ b/app/src/lib/git/checkout.ts @@ -24,12 +24,10 @@ async function getCheckoutArgs( account: IGitAccount | null, progressCallback?: ProgressCallback ) { - const networkArguments = await gitNetworkArguments(repository, account) - const baseArgs = progressCallback != null - ? [...networkArguments, 'checkout', '--progress'] - : [...networkArguments, 'checkout'] + ? [...gitNetworkArguments(), 'checkout', '--progress'] + : [...gitNetworkArguments(), 'checkout'] if (enableRecurseSubmodulesFlag()) { return branch.type === BranchType.Remote diff --git a/app/src/lib/git/clone.ts b/app/src/lib/git/clone.ts index 99dc79d9798..e05a2bf151e 100644 --- a/app/src/lib/git/clone.ts +++ b/app/src/lib/git/clone.ts @@ -31,14 +31,12 @@ export async function clone( options: CloneOptions, progressCallback?: (progress: ICloneProgress) => void ): Promise { - const networkArguments = await gitNetworkArguments(null, options.account) - const env = await envForRemoteOperation(options.account, url) const defaultBranch = options.defaultBranch ?? (await getDefaultBranch()) const args = [ - ...networkArguments, + ...gitNetworkArguments(), '-c', `init.defaultBranch=${defaultBranch}`, 'clone', diff --git a/app/src/lib/git/core.ts b/app/src/lib/git/core.ts index 6a437eef383..a3756b44d35 100644 --- a/app/src/lib/git/core.ts +++ b/app/src/lib/git/core.ts @@ -6,14 +6,8 @@ import { } from 'dugite' import { assertNever } from '../fatal-error' -import { getDotComAPIEndpoint } from '../api' - -import { IGitAccount } from '../../models/git-account' - import * as GitPerf from '../../ui/lib/git-perf' import * as Path from 'path' -import { Repository } from '../../models/repository' -import { getConfigValue, getGlobalConfigValue } from './config' import { isErrnoException } from '../errno-exception' import { ChildProcess } from 'child_process' import { Readable } from 'stream' @@ -446,57 +440,15 @@ function getDescriptionForError(error: DugiteError): string | null { * the default git configuration values provided by local, global, or system * level git configs. * - * These arguments should be inserted before the subcommand, i.e in - * the case of `git pull` these arguments needs to go before the `pull` - * argument. - * - * @param repository the local repository associated with the command, to check - * local, global and system config for an existing value. - * If `null` if provided (for example, when cloning a new - * repository), this function will check global and system - * config for an existing `protocol.version` setting - * - * @param account the identity associated with the repository, or `null` if - * unknown. The `protocol.version` behaviour is currently only - * enabled for GitHub.com repositories that don't have an - * existing `protocol.version` setting. + * These arguments should be inserted before the subcommand, i.e in the case of + * `git pull` these arguments needs to go before the `pull` argument. */ -export async function gitNetworkArguments( - repository: Repository | null, - account: IGitAccount | null -): Promise> { - const baseArgs = [ - // Explicitly unset any defined credential helper, we rely on our - // own askpass for authentication. - '-c', - 'credential.helper=', - ] - - if (account === null) { - return baseArgs - } - - const isDotComAccount = account.endpoint === getDotComAPIEndpoint() - - if (!isDotComAccount) { - return baseArgs - } - - const name = 'protocol.version' - - const protocolVersion = - repository != null - ? await getConfigValue(repository, name) - : await getGlobalConfigValue(name) - - if (protocolVersion !== null) { - // protocol.version is already set, we should not override it with our own - return baseArgs - } - - // opt in for v2 of the Git Wire protocol for GitHub repositories - return [...baseArgs, '-c', 'protocol.version=2'] -} +export const gitNetworkArguments = () => [ + // Explicitly unset any defined credential helper, we rely on our + // own askpass for authentication. + '-c', + 'credential.helper=', +] /** * Returns the arguments to use on any git operation that can end up diff --git a/app/src/lib/git/fetch.ts b/app/src/lib/git/fetch.ts index 821baa47044..0049df0296e 100644 --- a/app/src/lib/git/fetch.ts +++ b/app/src/lib/git/fetch.ts @@ -14,12 +14,10 @@ async function getFetchArgs( account: IGitAccount | null, progressCallback?: (progress: IFetchProgress) => void ) { - const networkArguments = await gitNetworkArguments(repository, account) - if (enableRecurseSubmodulesFlag()) { return progressCallback != null ? [ - ...networkArguments, + ...gitNetworkArguments(), 'fetch', '--progress', '--prune', @@ -27,7 +25,7 @@ async function getFetchArgs( remote, ] : [ - ...networkArguments, + ...gitNetworkArguments(), 'fetch', '--prune', '--recurse-submodules=on-demand', @@ -35,8 +33,8 @@ async function getFetchArgs( ] } else { return progressCallback != null - ? [...networkArguments, 'fetch', '--progress', '--prune', remote] - : [...networkArguments, 'fetch', '--prune', remote] + ? [...gitNetworkArguments(), 'fetch', '--progress', '--prune', remote] + : [...gitNetworkArguments(), 'fetch', '--prune', remote] } } @@ -119,16 +117,15 @@ export async function fetchRefspec( remote: IRemote, refspec: string ): Promise { - const options = { - successExitCodes: new Set([0, 128]), - env: await envForRemoteOperation(account, remote.url), - } - - const networkArguments = await gitNetworkArguments(repository, account) - - const args = [...networkArguments, 'fetch', remote.name, refspec] - - await git(args, repository.path, 'fetchRefspec', options) + await git( + [...gitNetworkArguments(), 'fetch', remote.name, refspec], + repository.path, + 'fetchRefspec', + { + successExitCodes: new Set([0, 128]), + env: await envForRemoteOperation(account, remote.url), + } + ) } export async function fastForwardBranches( diff --git a/app/src/lib/git/pull.ts b/app/src/lib/git/pull.ts index 9980b655dce..fa95a8c9104 100644 --- a/app/src/lib/git/pull.ts +++ b/app/src/lib/git/pull.ts @@ -21,14 +21,12 @@ async function getPullArgs( account: IGitAccount | null, progressCallback?: (progress: IPullProgress) => void ) { - const networkArguments = await gitNetworkArguments(repository, account) - const divergentPathArgs = await getDefaultPullDivergentBranchArguments( repository ) const args = [ - ...networkArguments, + ...gitNetworkArguments(), ...gitRebaseArguments(), 'pull', ...divergentPathArgs, diff --git a/app/src/lib/git/push.ts b/app/src/lib/git/push.ts index f9455d79c4d..eb81701baf1 100644 --- a/app/src/lib/git/push.ts +++ b/app/src/lib/git/push.ts @@ -60,10 +60,8 @@ export async function push( }, progressCallback?: (progress: IPushProgress) => void ): Promise { - const networkArguments = await gitNetworkArguments(repository, account) - const args = [ - ...networkArguments, + ...gitNetworkArguments(), 'push', remote.name, remoteBranch ? `${localBranch}:${remoteBranch}` : localBranch, diff --git a/app/src/lib/git/revert.ts b/app/src/lib/git/revert.ts index 581fb63bbfd..8cfeadd320a 100644 --- a/app/src/lib/git/revert.ts +++ b/app/src/lib/git/revert.ts @@ -26,9 +26,7 @@ export async function revertCommit( account: IGitAccount | null, progressCallback?: (progress: IRevertProgress) => void ) { - const networkArguments = await gitNetworkArguments(repository, account) - - const args = [...networkArguments, 'revert'] + const args = [...gitNetworkArguments(), 'revert'] if (commit.parentSHAs.length > 1) { args.push('-m', '1') } diff --git a/app/src/lib/git/tag.ts b/app/src/lib/git/tag.ts index f93a293a3cb..50f8d38c79b 100644 --- a/app/src/lib/git/tag.ts +++ b/app/src/lib/git/tag.ts @@ -90,10 +90,8 @@ export async function fetchTagsToPush( remote: IRemote, branchName: string ): Promise> { - const networkArguments = await gitNetworkArguments(repository, account) - const args = [ - ...networkArguments, + ...gitNetworkArguments(), 'push', remote.name, branchName,