* Push repository to a remote URL. * Used for GitHub migration - pushes all branches to the remote.
(
remoteUrl: string,
authToken: string
)
| 306 | * Used for GitHub migration - pushes all branches to the remote. |
| 307 | */ |
| 308 | async pushToRemote( |
| 309 | remoteUrl: string, |
| 310 | authToken: string |
| 311 | ): Promise<{ success: boolean; error?: string }> { |
| 312 | return withLogTags( |
| 313 | { source: 'GitRepositoryDO', tags: { appId: this.ctx.id.name } }, |
| 314 | async () => { |
| 315 | try { |
| 316 | if (!this.fs) { |
| 317 | await this.initializeFS(); |
| 318 | } |
| 319 | |
| 320 | if (!this._initialized || !this.fs) { |
| 321 | return { success: false, error: 'Repository not initialized' }; |
| 322 | } |
| 323 | |
| 324 | logger.info('Pushing repository to remote', { |
| 325 | id: this.ctx.id.toString(), |
| 326 | remoteUrl: sanitizeGitUrl(remoteUrl), |
| 327 | }); |
| 328 | |
| 329 | const gitObjs = this.fs.exportGitObjects(); |
| 330 | |
| 331 | if (gitObjs.length === 0) { |
| 332 | return { success: false, error: 'No git objects to push' }; |
| 333 | } |
| 334 | |
| 335 | // Build in-memory FS for isomorphic-git push operation |
| 336 | const memFs = new MemFS(); |
| 337 | await git.init({ fs: memFs, dir: '/', defaultBranch: 'main' }); |
| 338 | |
| 339 | for (const obj of gitObjs) { |
| 340 | await memFs.writeFile(obj.path, obj.data); |
| 341 | } |
| 342 | |
| 343 | let branches: string[] = []; |
| 344 | try { |
| 345 | branches = await git.listBranches({ fs: memFs, dir: '/' }); |
| 346 | } catch { |
| 347 | branches = ['main']; |
| 348 | } |
| 349 | |
| 350 | logger.info('Pushing branches to remote', { branches }); |
| 351 | |
| 352 | let mainPushed = false; |
| 353 | const failedBranches: string[] = []; |
| 354 | |
| 355 | for (const branch of branches) { |
| 356 | try { |
| 357 | await git.push({ |
| 358 | fs: memFs, |
| 359 | http, |
| 360 | dir: '/', |
| 361 | url: remoteUrl, |
| 362 | ref: branch, |
| 363 | remoteRef: branch, |
| 364 | onAuth: () => ({ username: 'x-access-token', password: authToken }), |
| 365 | force: false, |
no test coverage detected