Skip to content

Commit 5b8c7ca

Browse files
committed
mhutchie#547 Improved Git backwards compatibility when force deleting branches.
1 parent e1365c9 commit 5b8c7ca

File tree

2 files changed

+5
-9
lines changed

2 files changed

+5
-9
lines changed

src/dataSource.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -883,15 +883,11 @@ export class DataSource extends Disposable {
883883
* Delete a branch in a repository.
884884
* @param repo The path of the repository.
885885
* @param branchName The name of the branch.
886-
* @param forceDelete Should the delete be forced.
886+
* @param force Should force the branch to be deleted (even if not merged).
887887
* @returns The ErrorInfo from the executed command.
888888
*/
889-
public deleteBranch(repo: string, branchName: string, forceDelete: boolean) {
890-
let args = ['branch', '--delete'];
891-
if (forceDelete) args.push('--force');
892-
args.push(branchName);
893-
894-
return this.runGitCommand(args, repo);
889+
public deleteBranch(repo: string, branchName: string, force: boolean) {
890+
return this.runGitCommand(['branch', force ? '-D' : '-d', branchName], repo);
895891
}
896892

897893
/**

tests/dataSource.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5295,7 +5295,7 @@ describe('DataSource', () => {
52955295

52965296
// Assert
52975297
expect(result).toBe(null);
5298-
expect(spyOnSpawn).toBeCalledWith('/path/to/git', ['branch', '--delete', 'master'], expect.objectContaining({ cwd: '/path/to/repo' }));
5298+
expect(spyOnSpawn).toBeCalledWith('/path/to/git', ['branch', '-d', 'master'], expect.objectContaining({ cwd: '/path/to/repo' }));
52995299
});
53005300

53015301
it('Should force delete the branch', async () => {
@@ -5307,7 +5307,7 @@ describe('DataSource', () => {
53075307

53085308
// Assert
53095309
expect(result).toBe(null);
5310-
expect(spyOnSpawn).toBeCalledWith('/path/to/git', ['branch', '--delete', '--force', 'master'], expect.objectContaining({ cwd: '/path/to/repo' }));
5310+
expect(spyOnSpawn).toBeCalledWith('/path/to/git', ['branch', '-D', 'master'], expect.objectContaining({ cwd: '/path/to/repo' }));
53115311
});
53125312

53135313
it('Should return an error message thrown by git', async () => {

0 commit comments

Comments
 (0)