fix: harden reproducible checkout races
This commit is contained in:
@@ -72,28 +72,6 @@ export async function installHooks({
|
||||
activateHooks = async () => {
|
||||
await run('git', ['config', 'core.hooksPath', '.husky/_'], { cwd: root, stdio: 'inherit' });
|
||||
},
|
||||
readHooksPath = async () => {
|
||||
try {
|
||||
const { stdout } = await execFileAsync('git', ['config', '--get', 'core.hooksPath'], {
|
||||
cwd: root,
|
||||
});
|
||||
return stdout.trim() || null;
|
||||
} catch (error) {
|
||||
if (error.code === 1) return null;
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
restoreHooksPath = async (previous) => {
|
||||
if (previous === null) {
|
||||
try {
|
||||
await execFileAsync('git', ['config', '--unset', 'core.hooksPath'], { cwd: root });
|
||||
} catch (error) {
|
||||
if (error.code !== 5) throw error;
|
||||
}
|
||||
} else {
|
||||
await execFileAsync('git', ['config', 'core.hooksPath', previous], { cwd: root });
|
||||
}
|
||||
},
|
||||
} = {}) {
|
||||
if (disabled) return;
|
||||
|
||||
@@ -103,8 +81,6 @@ export async function installHooks({
|
||||
const stagingRepo = path.join(root, '.mosaic-test-work', `husky-stage-${nonce}`);
|
||||
const stagingHooks = path.join(stagingRepo, '.husky');
|
||||
const quarantined = path.join(quarantineRoot, `${path.basename(root)}-${nonce}`);
|
||||
|
||||
const previousHooksPath = await readHooksPath();
|
||||
await mkdir(huskyDir, { recursive: true });
|
||||
await mkdir(quarantineRoot, { recursive: true });
|
||||
|
||||
@@ -142,13 +118,6 @@ export async function installHooks({
|
||||
}
|
||||
} catch (error) {
|
||||
const cleanupFailures = [];
|
||||
try {
|
||||
if ((await pathExists(active)) && !previousComplete) {
|
||||
await rename(active, `${quarantined}-failed`);
|
||||
}
|
||||
} catch (cleanupError) {
|
||||
cleanupFailures.push(`active hooks: ${cleanupError.message}`);
|
||||
}
|
||||
try {
|
||||
if (await pathExists(stagingRepo)) {
|
||||
await rename(stagingRepo, `${quarantined}-staging`);
|
||||
@@ -156,11 +125,6 @@ export async function installHooks({
|
||||
} catch (cleanupError) {
|
||||
cleanupFailures.push(`staging hooks: ${cleanupError.message}`);
|
||||
}
|
||||
try {
|
||||
await restoreHooksPath(previousHooksPath);
|
||||
} catch (cleanupError) {
|
||||
cleanupFailures.push(`core.hooksPath: ${cleanupError.message}`);
|
||||
}
|
||||
const cleanup =
|
||||
cleanupFailures.length === 0
|
||||
? 'No partial hook set was activated.'
|
||||
|
||||
Reference in New Issue
Block a user