11
This commit is contained in:
@@ -285,15 +285,20 @@ describe('deleteLocalBranch', () => {
|
||||
})
|
||||
|
||||
it('treats a missing local branch as already deleted', async () => {
|
||||
execFile.mockImplementationOnce((_cmd, _args, _opts, cb) => {
|
||||
cb(new Error('missing'), '', '')
|
||||
})
|
||||
// heads 不存在 + remote-tracking 也不存在
|
||||
execFile
|
||||
.mockImplementationOnce((_cmd, _args, _opts, cb) => {
|
||||
cb(new Error('missing'), '', '')
|
||||
})
|
||||
.mockImplementationOnce((_cmd, _args, _opts, cb) => {
|
||||
cb(new Error('missing remote'), '', '')
|
||||
})
|
||||
const { deleteLocalBranch } = await import('../../src/git/branchSync.js')
|
||||
|
||||
const result = await deleteLocalBranch('/repo', 'feature/test')
|
||||
|
||||
expect(result).toEqual({ ok: true, stdout: '', stderr: '' })
|
||||
expect(execFile).toHaveBeenCalledOnce()
|
||||
expect(execFile).toHaveBeenCalledTimes(2)
|
||||
expect(execFile.mock.calls[0][1]).toEqual([
|
||||
'-C',
|
||||
'/repo',
|
||||
@@ -302,22 +307,36 @@ describe('deleteLocalBranch', () => {
|
||||
'--quiet',
|
||||
'refs/heads/feature/test',
|
||||
])
|
||||
expect(execFile.mock.calls[1][1]).toEqual([
|
||||
'-C',
|
||||
'/repo',
|
||||
'show-ref',
|
||||
'--verify',
|
||||
'--quiet',
|
||||
'refs/remotes/origin/feature/test',
|
||||
])
|
||||
})
|
||||
|
||||
it('deletes an existing local branch with git args instead of shell interpolation', async () => {
|
||||
execFile
|
||||
// show-ref heads: exists
|
||||
.mockImplementationOnce((_cmd, _args, _opts, cb) => {
|
||||
cb(null, '', '')
|
||||
})
|
||||
// branch -D
|
||||
.mockImplementationOnce((_cmd, _args, _opts, cb) => {
|
||||
cb(null, 'deleted', '')
|
||||
})
|
||||
// show-ref remotes: missing
|
||||
.mockImplementationOnce((_cmd, _args, _opts, cb) => {
|
||||
cb(new Error('missing remote'), '', '')
|
||||
})
|
||||
const { deleteLocalBranch } = await import('../../src/git/branchSync.js')
|
||||
|
||||
const result = await deleteLocalBranch('/repo', 'feature/weird name;rm -rf')
|
||||
|
||||
expect(result).toEqual({ ok: true, stdout: 'deleted', stderr: '' })
|
||||
expect(execFile).toHaveBeenCalledTimes(2)
|
||||
expect(execFile).toHaveBeenCalledTimes(3)
|
||||
expect(execFile.mock.calls[1][1]).toEqual([
|
||||
'-C',
|
||||
'/repo',
|
||||
|
||||
Reference in New Issue
Block a user