fix: address review findings (#1770)
This commit is contained in:
+69
-30
@@ -15,34 +15,65 @@ describe('git remote operations', () => {
|
||||
gitExecFileAsyncMock.mockReset()
|
||||
})
|
||||
|
||||
it('pushes with --set-upstream regardless of publish flag', async () => {
|
||||
// Why: every push uses --set-upstream so worktrees that were created
|
||||
// tracking the BASE ref (origin/main) get their upstream repointed to
|
||||
// origin/<branch> on first push. Without that the local branch keeps
|
||||
// tracking origin/main forever and the UI's ahead/behind read via
|
||||
// @{u} measures "ahead of base" rather than "ahead of remote branch".
|
||||
// Both publish=true and publish=false take the same path now; the
|
||||
// parameter is preserved in the signature for IPC compatibility but
|
||||
// is no longer load-bearing.
|
||||
it('pushes to origin when no upstream is configured', async () => {
|
||||
gitExecFileAsyncMock.mockResolvedValue({ stdout: '', stderr: '' })
|
||||
gitExecFileAsyncMock.mockRejectedValueOnce(Object.assign(new Error('no branch'), { code: 1 }))
|
||||
|
||||
await gitPush('/repo', true)
|
||||
await gitPush('/repo', false)
|
||||
|
||||
expect(gitExecFileAsyncMock).toHaveBeenNthCalledWith(
|
||||
1,
|
||||
['push', '--set-upstream', 'origin', 'HEAD'],
|
||||
{ cwd: '/repo' }
|
||||
)
|
||||
expect(gitExecFileAsyncMock).toHaveBeenNthCalledWith(
|
||||
2,
|
||||
expect(gitExecFileAsyncMock).toHaveBeenLastCalledWith(
|
||||
['push', '--set-upstream', 'origin', 'HEAD'],
|
||||
{ cwd: '/repo' }
|
||||
)
|
||||
})
|
||||
|
||||
it('pushes to the configured upstream remote and branch', async () => {
|
||||
gitExecFileAsyncMock
|
||||
.mockResolvedValueOnce({ stdout: 'review/pr-1738\n', stderr: '' })
|
||||
.mockResolvedValueOnce({ stdout: 'pr-prateek-orca\n', stderr: '' })
|
||||
.mockResolvedValueOnce({
|
||||
stdout: 'refs/heads/prateek/fix-sidebar-agents-toggle\n',
|
||||
stderr: ''
|
||||
})
|
||||
.mockResolvedValueOnce({ stdout: '', stderr: '' })
|
||||
|
||||
await gitPush('/repo', false)
|
||||
|
||||
expect(gitExecFileAsyncMock.mock.calls).toEqual([
|
||||
[['symbolic-ref', '--quiet', '--short', 'HEAD'], { cwd: '/repo' }],
|
||||
[['config', '--get', 'branch.review/pr-1738.remote'], { cwd: '/repo' }],
|
||||
[['config', '--get', 'branch.review/pr-1738.merge'], { cwd: '/repo' }],
|
||||
[
|
||||
['push', '--set-upstream', 'pr-prateek-orca', 'HEAD:prateek/fix-sidebar-agents-toggle'],
|
||||
{ cwd: '/repo' }
|
||||
]
|
||||
])
|
||||
})
|
||||
|
||||
it('uses an explicit push target even when it differs from the local branch name', async () => {
|
||||
gitExecFileAsyncMock
|
||||
.mockResolvedValueOnce({ stdout: '', stderr: '' })
|
||||
.mockResolvedValueOnce({ stdout: '', stderr: '' })
|
||||
|
||||
await gitPush('/repo', false, {
|
||||
remoteName: 'origin',
|
||||
branchName: 'contributor/fix-sidebar'
|
||||
})
|
||||
|
||||
expect(gitExecFileAsyncMock).toHaveBeenCalledWith(
|
||||
['push', '--set-upstream', 'origin', 'HEAD:contributor/fix-sidebar'],
|
||||
{ cwd: '/repo' }
|
||||
)
|
||||
expect(gitExecFileAsyncMock.mock.calls).toEqual([
|
||||
[['check-ref-format', '--branch', 'contributor/fix-sidebar'], { cwd: '/repo' }],
|
||||
[['push', '--set-upstream', 'origin', 'HEAD:contributor/fix-sidebar'], { cwd: '/repo' }]
|
||||
])
|
||||
})
|
||||
|
||||
it('maps non-fast-forward push failures to an actionable message', async () => {
|
||||
gitExecFileAsyncMock.mockRejectedValueOnce(new Error('remote rejected: non-fast-forward'))
|
||||
gitExecFileAsyncMock
|
||||
.mockRejectedValueOnce(new Error('no branch'))
|
||||
.mockRejectedValueOnce(new Error('remote rejected: non-fast-forward'))
|
||||
|
||||
await expect(gitPush('/repo', false)).rejects.toThrow(
|
||||
'Push rejected: remote has newer commits (non-fast-forward). Please pull or sync first.'
|
||||
@@ -50,19 +81,23 @@ describe('git remote operations', () => {
|
||||
})
|
||||
|
||||
it('passes through clean tail line when push error does not match known patterns', async () => {
|
||||
gitExecFileAsyncMock.mockRejectedValueOnce(
|
||||
new Error('Command failed: git push\nfatal: something obscure happened')
|
||||
)
|
||||
gitExecFileAsyncMock
|
||||
.mockRejectedValueOnce(new Error('no branch'))
|
||||
.mockRejectedValueOnce(
|
||||
new Error('Command failed: git push\nfatal: something obscure happened')
|
||||
)
|
||||
|
||||
await expect(gitPush('/repo', false)).rejects.toThrow('fatal: something obscure happened')
|
||||
})
|
||||
|
||||
it('strips embedded credentials from push error messages', async () => {
|
||||
gitExecFileAsyncMock.mockRejectedValueOnce(
|
||||
new Error(
|
||||
'Command failed: git push\nhttps://x-access-token:ghp_abc@github.com/foo/bar.git\nfatal: remote error'
|
||||
gitExecFileAsyncMock
|
||||
.mockRejectedValueOnce(new Error('no branch'))
|
||||
.mockRejectedValueOnce(
|
||||
new Error(
|
||||
'Command failed: git push\nhttps://x-access-token:ghp_abc@github.com/foo/bar.git\nfatal: remote error'
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
let caught: Error | undefined
|
||||
try {
|
||||
@@ -77,11 +112,13 @@ describe('git remote operations', () => {
|
||||
})
|
||||
|
||||
it('strips token-only credentials (https://TOKEN@host) from push error messages', async () => {
|
||||
gitExecFileAsyncMock.mockRejectedValueOnce(
|
||||
new Error(
|
||||
'Command failed: git push\nhttps://ghp_onlyToken@github.com/foo/bar.git\nfatal: remote error'
|
||||
gitExecFileAsyncMock
|
||||
.mockRejectedValueOnce(new Error('no branch'))
|
||||
.mockRejectedValueOnce(
|
||||
new Error(
|
||||
'Command failed: git push\nhttps://ghp_onlyToken@github.com/foo/bar.git\nfatal: remote error'
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
let caught: Error | undefined
|
||||
try {
|
||||
@@ -95,7 +132,9 @@ describe('git remote operations', () => {
|
||||
})
|
||||
|
||||
it('falls back to a generic message for non-Error rejections', async () => {
|
||||
gitExecFileAsyncMock.mockRejectedValueOnce('string')
|
||||
gitExecFileAsyncMock
|
||||
.mockRejectedValueOnce(new Error('no branch'))
|
||||
.mockRejectedValueOnce('string')
|
||||
|
||||
await expect(gitPush('/repo', false)).rejects.toThrow('Git remote operation failed.')
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user