Skip to content

Commit

Permalink
mhutchie#547 Improved Git backwards compatibility when force deleting…
Browse files Browse the repository at this point in the history
… branches.
  • Loading branch information
mhutchie authored and homsai committed Sep 7, 2022
1 parent 551aa68 commit 44de9f3
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
10 changes: 3 additions & 7 deletions src/dataSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions tests/dataSource.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand All @@ -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 () => {
Expand Down

0 comments on commit 44de9f3

Please sign in to comment.