(
pathToInspect: string,
options: EnsureRepositoryOptions = {}
)
| 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, |
nothing calls this directly
no test coverage detected