Repository: isomorphic-git/isomorphic-git (JavaScript)

Issue:
deleteBranch deletes tag
If a branch and tag have the same name, `deleteBranch` deletes the tag. A second call then deletes the branch.

```
$ isogit listBranches
[
  "main"
]
$ isogit branch --ref apple
$ isogit checkout --ref apple
$ isogit listBranches
[
  "apple",
  "main"
]
$ isogit tag --ref apple
$ isogit listTags
[
  "apple"
]
$ isogit checkout --ref main
$ isogit deleteBranch --ref apple
$ isogit listBranches
[
  "apple",
  "main"
]
$ isogit listTags
[]
$ isogit deleteBranch --ref apple
$ isogit listBranches
[
  "main"
]
```

`git` doesn't do this. It removes the branch and leaves the tag in place. This is what I'm going for, I want to make a tag then delete the branch to keep the branches list clean.

```sh
$ git branch
* main
$ git checkout -b apple
Switched to a new branch 'apple'
$ git branch
* apple
  main
$ git tag apple
$ git tag
apple
$ git checkout main
Switched to branch 'main'
$ git branch -d apple
Deleted branch apple (was 008d851).
$ git branch
* main
$ git tag
apple
```

I'm running in Node.


Discussion:
Thanks for the report, do you want to investigate the problem and maybe fix it?
Sure, I'll look into it :-)
:tada: This issue has been resolved in version 1.24.2 :tada:

The release is available on:
- [npm package (@latest dist-tag)](https://www.npmjs.com/package/isomorphic-git/v/1.24.2)
- [GitHub release](https://github.com/isomorphic-git/isomorphic-git/releases/tag/v1.24.2)

Your **[semantic-release](https://github.com/semantic-release/semantic-release)** bot :package::rocket:



Patch:
diff --git a/src/commands/deleteBranch.js b/src/commands/deleteBranch.js
index 3b7644996..b00ce93fb 100644
--- a/src/commands/deleteBranch.js
+++ b/src/commands/deleteBranch.js
@@ -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)
diff --git a/website/versioned_docs/version-1.x/listBranches.md b/website/versioned_docs/version-1.x/listBranches.md
index 49b5b9a8b..1ea2318b3 100644
--- a/website/versioned_docs/version-1.x/listBranches.md
+++ b/website/versioned_docs/version-1.x/listBranches.md
@@ -53,4 +53,4 @@ console.log('done')
     el.href = 'https://github.com/isomorphic-git/isomorphic-git/edit/main/src/api/listBranches.js';
   }
 })();
-</script>
+</script>
\ No newline at end of file


Test patch:
diff --git a/__tests__/__fixtures__/test-deleteBranch.git/refs/heads/collision b/__tests__/__fixtures__/test-deleteBranch.git/refs/heads/collision
new file mode 100644
index 000000000..89237f1d7
--- /dev/null
+++ b/__tests__/__fixtures__/test-deleteBranch.git/refs/heads/collision
@@ -0,0 +1,1 @@
+46938a722feab415225be56085fe08f233301211
diff --git a/__tests__/__fixtures__/test-deleteBranch.git/refs/tags/collision b/__tests__/__fixtures__/test-deleteBranch.git/refs/tags/collision
new file mode 100644
index 000000000..89237f1d7
--- /dev/null
+++ b/__tests__/__fixtures__/test-deleteBranch.git/refs/tags/collision
@@ -0,0 +1,1 @@
+46938a722feab415225be56085fe08f233301211
diff --git a/__tests__/test-deleteBranch.js b/__tests__/test-deleteBranch.js
index 1f856e38d..d06a66ccf 100644
--- a/__tests__/test-deleteBranch.js
+++ b/__tests__/test-deleteBranch.js
@@ -4,6 +4,7 @@ const {
   deleteBranch,
   currentBranch,
   listBranches,
+  listTags,
 } = require('isomorphic-git')
 
 const { makeFixture } = require('./__helpers__/FixtureFS.js')
@@ -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')