fix(git): simple-git use clone rather than exit (#12092)

Co-authored-by: Rhys Arkins <rhys@arkins.net>
This commit is contained in:
Steve King 2021-10-11 08:03:15 +01:00 committed by GitHub
parent 4327845702
commit 3d67812fea
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 27 additions and 5 deletions

View file

@ -7,6 +7,7 @@ import { ExternalHostError } from '../../types/errors/external-host-error';
import * as memCache from '../../util/cache/memory'; import * as memCache from '../../util/cache/memory';
import * as packageCache from '../../util/cache/package'; import * as packageCache from '../../util/cache/package';
import { privateCacheDir, readFile } from '../../util/fs'; import { privateCacheDir, readFile } from '../../util/fs';
import { simpleGitConfig } from '../../util/git/config';
import { Http } from '../../util/http'; import { Http } from '../../util/http';
import * as cargoVersioning from '../../versioning/cargo'; import * as cargoVersioning from '../../versioning/cargo';
import type { GetReleasesConfig, Release, ReleaseResult } from '../types'; import type { GetReleasesConfig, Release, ReleaseResult } from '../types';
@ -159,7 +160,7 @@ async function fetchRegistryInfo(
clonePath = join(privateCacheDir(), cacheDirFromUrl(url)); clonePath = join(privateCacheDir(), cacheDirFromUrl(url));
logger.info({ clonePath, registryUrl }, `Cloning private cargo registry`); logger.info({ clonePath, registryUrl }, `Cloning private cargo registry`);
const git = Git(); const git = Git(simpleGitConfig());
const clonePromise = git.clone(registryUrl, clonePath, { const clonePromise = git.clone(registryUrl, clonePath, {
'--depth': 1, '--depth': 1,
}); });

View file

@ -1,5 +1,6 @@
import simpleGit from 'simple-git'; import simpleGit from 'simple-git';
import * as packageCache from '../../util/cache/package'; import * as packageCache from '../../util/cache/package';
import { simpleGitConfig } from '../../util/git/config';
import { getRemoteUrlWithToken } from '../../util/git/url'; import { getRemoteUrlWithToken } from '../../util/git/url';
import * as semver from '../../versioning/semver'; import * as semver from '../../versioning/semver';
import type { DigestConfig, GetReleasesConfig, ReleaseResult } from '../types'; import type { DigestConfig, GetReleasesConfig, ReleaseResult } from '../types';
@ -17,7 +18,7 @@ export async function getRawRefs(
{ lookupName }: GetReleasesConfig, { lookupName }: GetReleasesConfig,
hostType: string hostType: string
): Promise<RawRefs[] | null> { ): Promise<RawRefs[] | null> {
const git = simpleGit(); const git = simpleGit(simpleGitConfig());
const cacheNamespace = 'git-raw-refs'; const cacheNamespace = 'git-raw-refs';
const cachedResult = await packageCache.get<RawRefs[]>( const cachedResult = await packageCache.get<RawRefs[]>(

View file

@ -4,6 +4,7 @@ import upath from 'upath';
import { getGlobalConfig } from '../../config/global'; import { getGlobalConfig } from '../../config/global';
import * as datasourceGitRefs from '../../datasource/git-refs'; import * as datasourceGitRefs from '../../datasource/git-refs';
import { logger } from '../../logger'; import { logger } from '../../logger';
import { simpleGitConfig } from '../../util/git/config';
import { getHttpUrl, getRemoteUrlWithToken } from '../../util/git/url'; import { getHttpUrl, getRemoteUrlWithToken } from '../../util/git/url';
import type { ExtractConfig, PackageFile } from '../types'; import type { ExtractConfig, PackageFile } from '../types';
import { GitModule } from './types'; import { GitModule } from './types';
@ -14,7 +15,7 @@ async function getUrl(
submoduleName: string submoduleName: string
): Promise<string> { ): Promise<string> {
const path = ( const path = (
await Git().raw([ await Git(simpleGitConfig()).raw([
'config', 'config',
'--file', '--file',
gitModulesPath, gitModulesPath,

View file

@ -0,0 +1,9 @@
import { simpleGitConfig } from './config';
describe('util/git/config', () => {
it('uses "close" events, ignores "exit" events from child processes', () => {
expect(simpleGitConfig()).toEqual({
completion: { onClose: true, onExit: false },
});
});
});

View file

@ -1,4 +1,5 @@
import is from '@sindresorhus/is'; import is from '@sindresorhus/is';
import { SimpleGitOptions } from 'simple-git';
export const enum GitNoVerifyOption { export const enum GitNoVerifyOption {
Commit = 'commit', Commit = 'commit',
@ -21,3 +22,12 @@ export function setNoVerify(value: GitNoVerifyOption[]): void {
export function getNoVerify(): GitNoVerifyOption[] { export function getNoVerify(): GitNoVerifyOption[] {
return noVerify; return noVerify;
} }
export function simpleGitConfig(): Partial<SimpleGitOptions> {
return {
completion: {
onClose: true,
onExit: false,
},
};
}

View file

@ -25,7 +25,7 @@ import { ExternalHostError } from '../../types/errors/external-host-error';
import { GitOptions, GitProtocol } from '../../types/git'; import { GitOptions, GitProtocol } from '../../types/git';
import { Limit, incLimitedValue } from '../../workers/global/limits'; import { Limit, incLimitedValue } from '../../workers/global/limits';
import { parseGitAuthor } from './author'; import { parseGitAuthor } from './author';
import { GitNoVerifyOption, getNoVerify } from './config'; import { GitNoVerifyOption, getNoVerify, simpleGitConfig } from './config';
import { configSigningKey, writePrivateKey } from './private-key'; import { configSigningKey, writePrivateKey } from './private-key';
export { GitNoVerifyOption, setNoVerify } from './config'; export { GitNoVerifyOption, setNoVerify } from './config';
@ -186,7 +186,7 @@ export async function initRepo(args: StorageConfig): Promise<void> {
config.additionalBranches = []; config.additionalBranches = [];
config.branchIsModified = {}; config.branchIsModified = {};
const { localDir } = getGlobalConfig(); const { localDir } = getGlobalConfig();
git = Git(localDir); git = Git(localDir, simpleGitConfig());
gitInitialized = false; gitInitialized = false;
await fetchBranchCommits(); await fetchBranchCommits();
} }