MCPcopy
hub / github.com/di-sukharev/opencommit / prepareEnvironment

Function prepareEnvironment

test/e2e/utils.ts:80–131  ·  view source on GitHub ↗
({
  remotes = 1
}: PrepareEnvironmentOptions = {})

Source from the content-addressed store, hash-verified

78};
79
80export const prepareEnvironment = async ({
81 remotes = 1
82}: PrepareEnvironmentOptions = {}): Promise<{
83 tempDir: string;
84 gitDir: string;
85 remoteDir?: string;
86 otherRemoteDir?: string;
87 cleanup: () => Promise<void>;
88}> => {
89 const tempDir = await prepareTempDir();
90 const gitDir = path.resolve(tempDir, 'test');
91 let remoteDir: string | undefined;
92 let otherRemoteDir: string | undefined;
93
94 if (remotes === 0) {
95 await fsExecFile('git', ['init', 'test'], { cwd: tempDir });
96 } else {
97 await fsExecFile('git', ['init', '--bare', 'remote.git'], {
98 cwd: tempDir
99 });
100 remoteDir = path.resolve(tempDir, 'remote.git');
101
102 if (remotes === 2) {
103 await fsExecFile('git', ['init', '--bare', 'other.git'], {
104 cwd: tempDir
105 });
106 otherRemoteDir = path.resolve(tempDir, 'other.git');
107 }
108
109 await fsExecFile('git', ['clone', 'remote.git', 'test'], { cwd: tempDir });
110
111 if (remotes === 2) {
112 await runGit(['remote', 'add', 'other', '../other.git'], gitDir);
113 }
114 }
115
116 await configureGitUser(gitDir);
117
118 const cleanup = async () => {
119 if (existsSync(tempDir)) {
120 await fsRemove(tempDir, { force: true, recursive: true });
121 }
122 };
123
124 return {
125 tempDir,
126 gitDir,
127 remoteDir,
128 otherRemoteDir,
129 cleanup
130 };
131};
132
133export const prepareTempDir = async (): Promise<string> => {
134 return fsMakeTempDir(path.join(tmpdir(), 'opencommit-test-'));

Callers 6

gitPush.test.tsFile · 0.90
noChanges.test.tsFile · 0.90
oneFile.test.tsFile · 0.90
commitlint.test.tsFile · 0.90

Calls 3

prepareTempDirFunction · 0.85
runGitFunction · 0.85
configureGitUserFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…