(remote = 'origin', { cwd, branch, dryRun })
| 71 | * @returns {Promise<any>} |
| 72 | */ |
| 73 | export async function gitPushUpstreamBranch(remote = 'origin', { cwd, branch, dryRun }) { |
| 74 | try { |
| 75 | const branchName = branch || 'master'; |
| 76 | console.log(`Preparing to push branch "${branchName}" to remote "${remote}"`); |
| 77 | |
| 78 | // If in dry run mode, just log the intended action |
| 79 | if (dryRun) { |
| 80 | console.log(`[DRY RUN] Would push ${branchName} to ${remote}`); |
| 81 | return; |
| 82 | } |
| 83 | |
| 84 | // Push strategies |
| 85 | const pushStrategies = [ |
| 86 | ['push', '-u', remote, branchName], |
| 87 | ['push', '--set-upstream', remote, branchName], |
| 88 | ['push', remote, branchName] |
| 89 | ]; |
| 90 | |
| 91 | for (const strategy of pushStrategies) { |
| 92 | try { |
| 93 | console.log(`$ git ${strategy.join(' ')}`); |
| 94 | return await execAsyncPiped('git', strategy, { cwd }, dryRun); |
| 95 | } catch (strategyError) { |
| 96 | console.warn(`❌ Push failed with strategy ${strategy.join(' ')}`, |
| 97 | strategyError.message || 'Unknown error'); |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | throw new Error('All push strategies failed'); |
| 102 | } catch (error) { |
| 103 | console.error('🚨 Upstream Push Error:', error.message); |
| 104 | throw error; |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | /** |
| 109 | * Check if there's anything uncommited |
no test coverage detected