Skip to content

Commit

Permalink
fix: Never delete tags in deleteBranch (#1777)
Browse files Browse the repository at this point in the history
  • Loading branch information
bojavou committed Jun 18, 2023
1 parent fb62b34 commit 936812a
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
46938a722feab415225be56085fe08f233301211
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
46938a722feab415225be56085fe08f233301211
12 changes: 12 additions & 0 deletions __tests__/test-deleteBranch.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const {
deleteBranch,
currentBranch,
listBranches,
listTags,
} = require('isomorphic-git')

const { makeFixture } = require('./__helpers__/FixtureFS.js')
Expand All @@ -18,6 +19,17 @@ describe('deleteBranch', () => {
expect(branches.includes('test')).toBe(false)
})

it('deletes the branch when an identically named tag exists', async () => {
// Setup
const { fs, gitdir } = await makeFixture('test-deleteBranch')
// Test
await deleteBranch({ fs, gitdir, ref: 'collision' })
const branches = await listBranches({ fs, gitdir })
expect(branches.includes('collision')).toBe(false)
const tags = await listTags({ fs, gitdir })
expect(tags.includes('collision')).toBe(true)
})

it('branch not exist', async () => {
// Setup
const { fs, gitdir } = await makeFixture('test-deleteBranch')
Expand Down
1 change: 1 addition & 0 deletions src/commands/deleteBranch.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { GitRefManager } from '../managers/GitRefManager.js'
* @returns {Promise<void>}
*/
export async function _deleteBranch({ fs, gitdir, ref }) {
ref = ref.startsWith('refs/heads/') ? ref : `refs/heads/${ref}`
const exist = await GitRefManager.exists({ fs, gitdir, ref })
if (!exist) {
throw new NotFoundError(ref)
Expand Down
2 changes: 1 addition & 1 deletion website/versioned_docs/version-1.x/listBranches.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,4 @@ console.log('done')
el.href = 'https://github.com/isomorphic-git/isomorphic-git/edit/main/src/api/listBranches.js';
}
})();
</script>
</script>

0 comments on commit 936812a

Please sign in to comment.