@@ -24,92 +24,3 @@ func GetBranch(repo *models.Repository, branch string) (*git.Branch, error) {
2424
2525 return gitRepo .GetBranch (branch )
2626}
27-
28- // GetBranches returns branches from the repository, skipping skip initial branches and
29- // returning at most limit branches, or all branches if limit is 0.
30- func GetBranches (repo * models.Repository , skip , limit int ) ([]* git.Branch , int , error ) {
31- return git .GetBranchesByPath (repo .RepoPath (), skip , limit )
32- }
33-
34- // checkBranchName validates branch name with existing repository branches
35- func checkBranchName (repo * models.Repository , name string ) error {
36- gitRepo , err := git .OpenRepository (repo .RepoPath ())
37- if err != nil {
38- return err
39- }
40- defer gitRepo .Close ()
41-
42- branches , _ , err := GetBranches (repo , 0 , 0 )
43- if err != nil {
44- return err
45- }
46-
47- for _ , branch := range branches {
48- if branch .Name == name {
49- return models.ErrBranchAlreadyExists {
50- BranchName : branch .Name ,
51- }
52- } else if (len (branch .Name ) < len (name ) && branch .Name + "/" == name [0 :len (branch .Name )+ 1 ]) ||
53- (len (branch .Name ) > len (name ) && name + "/" == branch .Name [0 :len (name )+ 1 ]) {
54- return models.ErrBranchNameConflict {
55- BranchName : branch .Name ,
56- }
57- }
58- }
59-
60- if _ , err := gitRepo .GetTag (name ); err == nil {
61- return models.ErrTagAlreadyExists {
62- TagName : name ,
63- }
64- }
65-
66- return nil
67- }
68-
69- // CreateNewBranch creates a new repository branch
70- func CreateNewBranch (doer * models.User , repo * models.Repository , oldBranchName , branchName string ) (err error ) {
71- // Check if branch name can be used
72- if err := checkBranchName (repo , branchName ); err != nil {
73- return err
74- }
75-
76- if ! git .IsBranchExist (repo .RepoPath (), oldBranchName ) {
77- return models.ErrBranchDoesNotExist {
78- BranchName : oldBranchName ,
79- }
80- }
81-
82- if err := git .Push (repo .RepoPath (), git.PushOptions {
83- Remote : repo .RepoPath (),
84- Branch : fmt .Sprintf ("%s:%s%s" , oldBranchName , git .BranchPrefix , branchName ),
85- Env : models .PushingEnvironment (doer , repo ),
86- }); err != nil {
87- if git .IsErrPushOutOfDate (err ) || git .IsErrPushRejected (err ) {
88- return err
89- }
90- return fmt .Errorf ("Push: %v" , err )
91- }
92-
93- return nil
94- }
95-
96- // CreateNewBranchFromCommit creates a new repository branch
97- func CreateNewBranchFromCommit (doer * models.User , repo * models.Repository , commit , branchName string ) (err error ) {
98- // Check if branch name can be used
99- if err := checkBranchName (repo , branchName ); err != nil {
100- return err
101- }
102-
103- if err := git .Push (repo .RepoPath (), git.PushOptions {
104- Remote : repo .RepoPath (),
105- Branch : fmt .Sprintf ("%s:%s%s" , commit , git .BranchPrefix , branchName ),
106- Env : models .PushingEnvironment (doer , repo ),
107- }); err != nil {
108- if git .IsErrPushOutOfDate (err ) || git .IsErrPushRejected (err ) {
109- return err
110- }
111- return fmt .Errorf ("Push: %v" , err )
112- }
113-
114- return nil
115- }
0 commit comments