mirror of
https://github.com/di-sukharev/opencommit.git
synced 2026-01-13 15:47:58 -05:00
* 378: fix hook env (#402) * fix(prepare-commit-msg-hook): update error handling to provide clearer instructions for setting API keys and improve user guidance * Fix: a bug that causes an error when pushing without setting git remote (#396) * refactoring v2 (#408) * 3.2.0 * update deploy commands --------- Co-authored-by: Takanori Matsumoto <matscube@gmail.com>
38 lines
1.1 KiB
TypeScript
38 lines
1.1 KiB
TypeScript
import path from 'path'
|
|
import { mkdtemp, rm } from 'fs'
|
|
import { promisify } from 'util';
|
|
import { tmpdir } from 'os';
|
|
import { exec } from 'child_process';
|
|
const fsMakeTempDir = promisify(mkdtemp);
|
|
const fsExec = promisify(exec);
|
|
const fsRemove = promisify(rm);
|
|
|
|
/**
|
|
* Prepare the environment for the test
|
|
* Create a temporary git repository in the temp directory
|
|
*/
|
|
export const prepareEnvironment = async (): Promise<{
|
|
gitDir: string;
|
|
cleanup: () => Promise<void>;
|
|
}> => {
|
|
const tempDir = await prepareTempDir();
|
|
// Create a remote git repository int the temp directory. This is necessary to execute the `git push` command
|
|
await fsExec('git init --bare remote.git', { cwd: tempDir });
|
|
await fsExec('git clone remote.git test', { cwd: tempDir });
|
|
const gitDir = path.resolve(tempDir, 'test');
|
|
|
|
const cleanup = async () => {
|
|
return fsRemove(tempDir, { recursive: true });
|
|
}
|
|
return {
|
|
gitDir,
|
|
cleanup,
|
|
}
|
|
}
|
|
|
|
export const prepareTempDir = async(): Promise<string> => {
|
|
return await fsMakeTempDir(path.join(tmpdir(), 'opencommit-test-'));
|
|
}
|
|
|
|
export const wait = (ms: number) => new Promise(resolve => setTimeout(resolve, ms));
|