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

Commit eddb761

Browse files
alexschneiderAlex Schneider
andauthored
fix: scenario where branchPosition is not in upstream (#162)
Co-authored-by: Alex Schneider <[email protected]>
1 parent 004af70 commit eddb761

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/git/remoteNameAndBranch.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,5 +61,15 @@ describe('git', () => {
6161
assert.strictEqual(remoteName, 'remote-one', 'incorrect remote name')
6262
assert.strictEqual(branch, 'feature', 'incorrect branch name')
6363
})
64+
65+
it('falls back to first remote and branch when branch is not pushed to upstream', async () => {
66+
const { remoteName, branch } = await gitRemoteNameAndBranch(
67+
'',
68+
createMockGitHelpers(['origin'], 'feature', 'origin/master')
69+
)
70+
71+
assert.strictEqual(remoteName, 'origin', 'incorrect remote name')
72+
assert.strictEqual(branch, 'feature', 'incorrect branch name')
73+
})
6474
})
6575
})

src/git/remoteNameAndBranch.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export async function gitRemoteNameAndBranch(
4848

4949
const branchPosition = upstreamAndBranch.lastIndexOf(branch)
5050
const maybeRemote = upstreamAndBranch.slice(0, branchPosition - 1)
51-
if (maybeRemote) {
51+
if (branchPosition !== -1 && maybeRemote) {
5252
remoteName = maybeRemote
5353
}
5454
} catch {

0 commit comments

Comments
 (0)