Skip to content

git: repository, fix DeleteBranch failing with full ref name#1951

Merged
pjbgf merged 1 commit into
go-git:mainfrom
tmchow:osc/1189-fix-delete-branch-ref-name
Apr 2, 2026
Merged

git: repository, fix DeleteBranch failing with full ref name#1951
pjbgf merged 1 commit into
go-git:mainfrom
tmchow:osc/1189-fix-delete-branch-ref-name

Conversation

@tmchow
Copy link
Copy Markdown
Contributor

@tmchow tmchow commented Apr 2, 2026

Description

DeleteBranch("refs/heads/test") returns ErrBranchNotFound even when the branch exists. This happens because Branches() returns full reference names but DeleteBranch() looks up cfg.Branches by short name only.

The fix strips the refs/heads/ prefix before the config lookup, so both DeleteBranch("test") and DeleteBranch("refs/heads/test") work. This matches git branch -d which accepts both forms.

Link to tracking issue

Fixes #1189

Testing

Added TestDeleteBranchFullRefName which creates a branch and deletes it using the full refs/heads/ name.

go test ./... and go vet ./... pass.

Documentation

N/A

This contribution was developed with AI assistance (Codex).

Strip refs/heads/ prefix from the branch name before looking up the
config, so callers can pass either short names or full reference names.

Fixes go-git#1189
Copy link
Copy Markdown
Member

@pjbgf pjbgf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tmchow thanks for working on this. 🙇

@pjbgf pjbgf merged commit ce42681 into go-git:main Apr 2, 2026
16 checks passed
@tmchow
Copy link
Copy Markdown
Contributor Author

tmchow commented Apr 3, 2026

Thanks for the quick merge!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Can't delete a branch that for sure exists

2 participants