mirror of
https://codeberg.org/davrot/forgejo.git
synced 2025-05-30 09:00:02 +02:00
New UI merge in progress
This commit is contained in:
parent
0a739cf9ac
commit
8dd07c0ddd
199 changed files with 15030 additions and 9325 deletions
38
modules/git/repo_branch.go
Normal file
38
modules/git/repo_branch.go
Normal file
|
@ -0,0 +1,38 @@
|
|||
// Copyright 2014 The Gogs Authors. All rights reserved.
|
||||
// Use of this source code is governed by a MIT-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package git
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"strings"
|
||||
|
||||
"github.com/Unknwon/com"
|
||||
)
|
||||
|
||||
func IsBranchExist(repoPath, branchName string) bool {
|
||||
_, _, err := com.ExecCmdDir(repoPath, "git", "show-ref", "--verify", "refs/heads/"+branchName)
|
||||
return err == nil
|
||||
}
|
||||
|
||||
func (repo *Repository) IsBranchExist(branchName string) bool {
|
||||
return IsBranchExist(repo.Path, branchName)
|
||||
}
|
||||
|
||||
func (repo *Repository) GetBranches() ([]string, error) {
|
||||
stdout, stderr, err := com.ExecCmdDir(repo.Path, "git", "show-ref", "--heads")
|
||||
if err != nil {
|
||||
return nil, errors.New(stderr)
|
||||
}
|
||||
infos := strings.Split(stdout, "\n")
|
||||
branches := make([]string, len(infos)-1)
|
||||
for i, info := range infos[:len(infos)-1] {
|
||||
parts := strings.Split(info, " ")
|
||||
if len(parts) != 2 {
|
||||
continue // NOTE: I should believe git will not give me wrong string.
|
||||
}
|
||||
branches[i] = strings.TrimPrefix(parts[1], "refs/heads/")
|
||||
}
|
||||
return branches, nil
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue