1
0
Fork 0
forked from forgejo/forgejo

update code.gitea.io/git (#450)

This commit is contained in:
Lunny Xiao 2016-12-22 17:30:52 +08:00 committed by Thomas Boerger
parent 0c5c34d7dd
commit 47a7529d96
36 changed files with 509 additions and 480 deletions

View file

@ -11,7 +11,8 @@ import (
"github.com/mcuadros/go-version"
)
const BRANCH_PREFIX = "refs/heads/"
// BranchPrefix base dir of the branch information file store on git
const BranchPrefix = "refs/heads/"
// IsReferenceExist returns true if given reference exists in the repository.
func IsReferenceExist(repoPath, name string) bool {
@ -21,9 +22,10 @@ func IsReferenceExist(repoPath, name string) bool {
// IsBranchExist returns true if given branch exists in the repository.
func IsBranchExist(repoPath, name string) bool {
return IsReferenceExist(repoPath, BRANCH_PREFIX+name)
return IsReferenceExist(repoPath, BranchPrefix+name)
}
// IsBranchExist returns true if given branch exists in current repository.
func (repo *Repository) IsBranchExist(name string) bool {
return IsBranchExist(repo.Path, name)
}
@ -42,12 +44,12 @@ func (repo *Repository) GetHEADBranch() (*Branch, error) {
}
stdout = strings.TrimSpace(stdout)
if !strings.HasPrefix(stdout, BRANCH_PREFIX) {
if !strings.HasPrefix(stdout, BranchPrefix) {
return nil, fmt.Errorf("invalid HEAD branch: %v", stdout)
}
return &Branch{
Name: stdout[len(BRANCH_PREFIX):],
Name: stdout[len(BranchPrefix):],
Path: stdout,
}, nil
}
@ -58,7 +60,7 @@ func (repo *Repository) SetDefaultBranch(name string) error {
return ErrUnsupportedVersion{"1.7.10"}
}
_, err := NewCommand("symbolic-ref", "HEAD", BRANCH_PREFIX+name).RunInDir(repo.Path)
_, err := NewCommand("symbolic-ref", "HEAD", BranchPrefix+name).RunInDir(repo.Path)
return err
}
@ -76,12 +78,12 @@ func (repo *Repository) GetBranches() ([]string, error) {
if len(fields) != 2 {
continue // NOTE: I should believe git will not give me wrong string.
}
branches[i] = strings.TrimPrefix(fields[1], BRANCH_PREFIX)
branches[i] = strings.TrimPrefix(fields[1], BranchPrefix)
}
return branches, nil
}
// Option(s) for delete branch
// DeleteBranchOptions Option(s) for delete branch
type DeleteBranchOptions struct {
Force bool
}