MCPcopy
hub / github.com/generalaction/emdash / ensureRepository

Method ensureRepository

packages/core/src/git/git-runtime.ts:95–130  ·  view source on GitHub ↗
(
    pathToInspect: string,
    options: EnsureRepositoryOptions = {}
  )

Source from the content-addressed store, hash-verified

93 }
94
95 async ensureRepository(
96 pathToInspect: string,
97 options: EnsureRepositoryOptions = {}
98 ): Promise<Result<GitRepositoryInfo, EnsureRepositoryError>> {
99 this.assertOpen();
100 const resolvedPath = path.resolve(pathToInspect);
101 const inspected = await this.inspectResolvedPath(resolvedPath);
102 if (inspected.kind === 'repository') return ok(inspected);
103 if (inspected.kind === 'inspect-failed') {
104 return err({ type: 'inspect-failed', path: inspected.path, message: inspected.message });
105 }
106 if (!options.initIfMissing) {
107 return err({ type: 'not-repository', path: inspected.path });
108 }
109
110 try {
111 await this.exec.withCwd(resolvedPath).exec(['init']);
112 } catch (error) {
113 return err({ type: 'init-failed', path: resolvedPath, message: gitErrorMessage(error) });
114 }
115
116 const initialized = await this.inspectResolvedPath(resolvedPath);
117 if (initialized.kind === 'repository') return ok(initialized);
118 if (initialized.kind === 'inspect-failed') {
119 return err({
120 type: 'inspect-failed',
121 path: initialized.path,
122 message: initialized.message,
123 });
124 }
125 return err({
126 type: 'init-failed',
127 path: resolvedPath,
128 message: 'Failed to initialize git repository',
129 });
130 }
131
132 async cloneRepository(
133 repositoryUrl: string,

Callers

nothing calls this directly

Calls 8

assertOpenMethod · 0.95
inspectResolvedPathMethod · 0.95
okFunction · 0.90
errFunction · 0.90
gitErrorMessageFunction · 0.90
resolveMethod · 0.65
execMethod · 0.65
withCwdMethod · 0.45

Tested by

no test coverage detected