Skip to content
This repository has been archived by the owner on Mar 10, 2022. It is now read-only.

Commit

Permalink
fix: scenario where branchPosition is not in upstream (#162)
Browse files Browse the repository at this point in the history
Co-authored-by: Alex Schneider <[email protected]>
  • Loading branch information
alexschneider and Alex Schneider authored Apr 5, 2021
1 parent 004af70 commit eddb761
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/git/remoteNameAndBranch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,15 @@ describe('git', () => {
assert.strictEqual(remoteName, 'remote-one', 'incorrect remote name')
assert.strictEqual(branch, 'feature', 'incorrect branch name')
})

it('falls back to first remote and branch when branch is not pushed to upstream', async () => {
const { remoteName, branch } = await gitRemoteNameAndBranch(
'',
createMockGitHelpers(['origin'], 'feature', 'origin/master')
)

assert.strictEqual(remoteName, 'origin', 'incorrect remote name')
assert.strictEqual(branch, 'feature', 'incorrect branch name')
})
})
})
2 changes: 1 addition & 1 deletion src/git/remoteNameAndBranch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export async function gitRemoteNameAndBranch(

const branchPosition = upstreamAndBranch.lastIndexOf(branch)
const maybeRemote = upstreamAndBranch.slice(0, branchPosition - 1)
if (maybeRemote) {
if (branchPosition !== -1 && maybeRemote) {
remoteName = maybeRemote
}
} catch {
Expand Down

0 comments on commit eddb761

Please sign in to comment.