1
0
Fork 0
forked from forgejo/forgejo

Update code.gitea.io/git (#1824)

* Update code.gitea.io/git

* Update function calls

* govendor fetch
This commit is contained in:
Ethan Koenig 2017-05-30 05:32:01 -04:00 committed by Bo-Yi Wu
parent 367ff327ed
commit 474d636794
11 changed files with 209 additions and 126 deletions

View file

@ -66,19 +66,15 @@ func (repo *Repository) SetDefaultBranch(name string) error {
// GetBranches returns all branches of the repository.
func (repo *Repository) GetBranches() ([]string, error) {
stdout, err := NewCommand("show-ref", "--heads").RunInDir(repo.Path)
stdout, err := NewCommand("for-each-ref", "--format=%(refname)", BranchPrefix).RunInDir(repo.Path)
if err != nil {
return nil, err
}
infos := strings.Split(stdout, "\n")
branches := make([]string, len(infos)-1)
for i, info := range infos[:len(infos)-1] {
fields := strings.Fields(info)
if len(fields) != 2 {
continue // NOTE: I should believe git will not give me wrong string.
}
branches[i] = strings.TrimPrefix(fields[1], BranchPrefix)
refs := strings.Split(stdout, "\n")
branches := make([]string, len(refs)-1)
for i, ref := range refs[:len(refs)-1] {
branches[i] = strings.TrimPrefix(ref, BranchPrefix)
}
return branches, nil
}