[PR #39] [MERGED] Return empty list of branches if repository is bare. #47

Closed
opened 2026-02-16 10:23:57 -05:00 by yindo · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/go-gitea/git/pull/39
Author: @cybe
Created: 3/24/2017
Status: Merged
Merged: 5/26/2017
Merged by: @lunny

Base: masterHead: handle_bare_repos


📝 Commits (1)

  • 98a4dfb Return empty list of branches if repository is bare.

📊 Changes

1 file changed (+5 additions, -9 deletions)

View changed files

📝 repo_branch.go (+5 -9)

📄 Description

This pull request enables the git module to handle bare (empty) repositories when getting all branches of a repository. This failed previously, because the command to retrieve the branches git show-ref --heads exited with return code 1 which resulted in a non-nil error.

The new implementation uses git for-each-ref to iterate over all branches and outputs nothing in case the repository is bare while using a return code of 0. As the output format changed (and now is much simpler), the parsing of that output had to be changed as well.

This is in preparation of a coming pull request to gitea itself to gracefully handle bare repositories on various API operations instead of throwing HTTP-500 errors.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/go-gitea/git/pull/39 **Author:** [@cybe](https://github.com/cybe) **Created:** 3/24/2017 **Status:** ✅ Merged **Merged:** 5/26/2017 **Merged by:** [@lunny](https://github.com/lunny) **Base:** `master` ← **Head:** `handle_bare_repos` --- ### 📝 Commits (1) - [`98a4dfb`](https://github.com/go-gitea/git/commit/98a4dfbd9aaed44480a2e2e57af37aaf2f074e06) Return empty list of branches if repository is bare. ### 📊 Changes **1 file changed** (+5 additions, -9 deletions) <details> <summary>View changed files</summary> 📝 `repo_branch.go` (+5 -9) </details> ### 📄 Description This pull request enables the git module to handle bare (empty) repositories when getting all branches of a repository. This failed previously, because the command to retrieve the branches `git show-ref --heads` exited with return code `1` which resulted in a non-nil error. The new implementation uses `git for-each-ref` to iterate over all branches and outputs nothing in case the repository is bare while using a return code of `0`. As the output format changed (and now is much simpler), the parsing of that output had to be changed as well. This is in preparation of a coming pull request to gitea itself to [gracefully handle bare repositories on various API operations](https://github.com/cybe/gitea/commit/9f0e75a70b4415bd5be0a49586996d34961dfa7d) instead of throwing HTTP-500 errors. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
yindo added the pull-request label 2026-02-16 10:23:57 -05:00
yindo closed this issue 2026-02-16 10:23:57 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: go-gitea/git#47