({ directory, fs, gitDirectory, credentialsId, uri = '', repoId, legacyDiff = false, ref }: InitOptions)
| 148 | _baseOpts: BaseOpts = gitCallbacks(); |
| 149 | |
| 150 | async init({ directory, fs, gitDirectory, credentialsId, uri = '', repoId, legacyDiff = false, ref }: InitOptions) { |
| 151 | this._baseOpts = { |
| 152 | ...this._baseOpts, |
| 153 | dir: directory, |
| 154 | ...gitCallbacks(credentialsId), |
| 155 | gitdir: gitDirectory, |
| 156 | fs, |
| 157 | http: httpClient, |
| 158 | uri, |
| 159 | repoId, |
| 160 | legacyDiff, |
| 161 | ref, |
| 162 | }; |
| 163 | |
| 164 | if (await this.repoExists()) { |
| 165 | console.log(`[git] Opened repo for ${gitDirectory}`); |
| 166 | } else { |
| 167 | console.log(`[git] Initialized repo in ${gitDirectory}`); |
| 168 | let defaultBranch = 'main'; |
| 169 | |
| 170 | try { |
| 171 | const url = await this.getRemoteOriginURI(); |
| 172 | if (!url) { |
| 173 | throw new Error('No remote origin URL'); |
| 174 | } |
| 175 | const [mainRef] = await git.listServerRefs({ |
| 176 | ...this._baseOpts, |
| 177 | url, |
| 178 | prefix: 'HEAD', |
| 179 | symrefs: true, |
| 180 | }); |
| 181 | |
| 182 | defaultBranch = mainRef?.target?.replace('refs/heads/', '') || 'main'; |
| 183 | } catch { |
| 184 | // Ignore error |
| 185 | } |
| 186 | |
| 187 | await git.init({ ...this._baseOpts, defaultBranch }); |
| 188 | } |
| 189 | } |
| 190 | |
| 191 | async getRemoteOriginURI() { |
| 192 | try { |
nothing calls this directly
no test coverage detected