Skip to content

Commit

Permalink
fix(lib): don't push main if it already exists in remote
Browse files Browse the repository at this point in the history
  • Loading branch information
good-idea committed Feb 3, 2021
1 parent a1ce801 commit 904f7f8
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,14 @@ async function main() {

/* Make sure we are on the master branch */
let currentBranch = await getCurrentBranch()
const branchNames = await getLocalBranches()
const [branchNames, hasRemoteOrigin, remoteBranchNames] = await Promise.all([
getLocalBranches(),
hasRemote('origin'),
getRemoteBranchNames(),
])
const localHasMaster = branchNames.includes('master')
const hasRemoteOrigin = await hasRemote('origin')
const remoteBranchNames = await getRemoteBranchNames()
const remoteHasMaster = remoteBranchNames.includes('master')
const remoteHasMain = remoteBranchNames.includes('main')

if (localHasMaster) {
if (currentBranch !== 'master') {
Expand Down Expand Up @@ -123,9 +126,11 @@ async function main() {
}

if (hasRemoteOrigin) {
/* Set the upstream */
log('Setting the upstream..')
await exec('git', ['push', '-u', 'origin', 'main'])
if (remoteHasMain === false) {
/* Set the upstream */
log('Setting the upstream..')
await exec('git', ['push', '-u', 'origin', 'main'])
}
/* Update the tracking branch */
log('Updating the tracking branch..')
await exec('git', ['branch', '-u', 'origin/main', 'main'])
Expand Down

0 comments on commit 904f7f8

Please sign in to comment.