Skip to content
This repository was archived by the owner on Apr 12, 2019. It is now read-only.

Return empty list of branches if repository is bare. #39

Merged
merged 1 commit into from
May 26, 2017
Merged

Return empty list of branches if repository is bare. #39

merged 1 commit into from
May 26, 2017

Conversation

cybe
Copy link

@cybe cybe commented Mar 24, 2017

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.

@ethantkoenig
Copy link
Member

LGTM

However, we should be careful when updating gitea with these changes, because some places (e.g. RepoRef in modules/context/repo.go) assume that GetBranches() will return a non-empty slice.

@ethantkoenig
Copy link
Member

See also go-gitea/gitea#1706

@lunny
Copy link
Member

lunny commented May 23, 2017

@ethantkoenig did you mean this will fix go-gitea/gitea#1706 ?

@ethantkoenig
Copy link
Member

Sorry, should have been more clear. It will prevent the error from occurring, but we'll need to change some code in modules/context/repo.go to account for the fact that GetBranches() may return an empty slice.

@lunny
Copy link
Member

lunny commented May 25, 2017

LGTM, maybe need some tests.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants