From 5b8c7cafd25edccd9acaee77756c7381a51832fd Mon Sep 17 00:00:00 2001 From: Michael Hutchison Date: Sat, 18 Sep 2021 19:15:33 +1000 Subject: [PATCH] #547 Improved Git backwards compatibility when force deleting branches. --- src/dataSource.ts | 10 +++------- tests/dataSource.test.ts | 4 ++-- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/src/dataSource.ts b/src/dataSource.ts index a695e3e5..10a3429f 100644 --- a/src/dataSource.ts +++ b/src/dataSource.ts @@ -883,15 +883,11 @@ export class DataSource extends Disposable { * Delete a branch in a repository. * @param repo The path of the repository. * @param branchName The name of the branch. - * @param forceDelete Should the delete be forced. + * @param force Should force the branch to be deleted (even if not merged). * @returns The ErrorInfo from the executed command. */ - public deleteBranch(repo: string, branchName: string, forceDelete: boolean) { - let args = ['branch', '--delete']; - if (forceDelete) args.push('--force'); - args.push(branchName); - - return this.runGitCommand(args, repo); + public deleteBranch(repo: string, branchName: string, force: boolean) { + return this.runGitCommand(['branch', force ? '-D' : '-d', branchName], repo); } /** diff --git a/tests/dataSource.test.ts b/tests/dataSource.test.ts index b092d7c7..240d9a3f 100644 --- a/tests/dataSource.test.ts +++ b/tests/dataSource.test.ts @@ -5295,7 +5295,7 @@ describe('DataSource', () => { // Assert expect(result).toBe(null); - expect(spyOnSpawn).toBeCalledWith('/path/to/git', ['branch', '--delete', 'master'], expect.objectContaining({ cwd: '/path/to/repo' })); + expect(spyOnSpawn).toBeCalledWith('/path/to/git', ['branch', '-d', 'master'], expect.objectContaining({ cwd: '/path/to/repo' })); }); it('Should force delete the branch', async () => { @@ -5307,7 +5307,7 @@ describe('DataSource', () => { // Assert expect(result).toBe(null); - expect(spyOnSpawn).toBeCalledWith('/path/to/git', ['branch', '--delete', '--force', 'master'], expect.objectContaining({ cwd: '/path/to/repo' })); + expect(spyOnSpawn).toBeCalledWith('/path/to/git', ['branch', '-D', 'master'], expect.objectContaining({ cwd: '/path/to/repo' })); }); it('Should return an error message thrown by git', async () => {