@@ -7,7 +7,6 @@ package git
77import (
88 "context"
99 "errors"
10- "fmt"
1110 "strings"
1211)
1312
@@ -25,36 +24,6 @@ func IsBranchExist(ctx context.Context, repoPath, name string) bool {
2524 return IsReferenceExist (ctx , repoPath , BranchPrefix + name )
2625}
2726
28- // Branch represents a Git branch.
29- type Branch struct {
30- Name string
31- Path string
32- 33- gitRepo * Repository
34- }
35- 36- // GetHEADBranch returns corresponding branch of HEAD.
37- func (repo * Repository ) GetHEADBranch () (* Branch , error ) {
38- if repo == nil {
39- return nil , errors .New ("nil repo" )
40- }
41- stdout , _ , err := NewCommand ("symbolic-ref" , "HEAD" ).RunStdString (repo .Ctx , & RunOpts {Dir : repo .Path })
42- if err != nil {
43- return nil , err
44- }
45- stdout = strings .TrimSpace (stdout )
46- 47- if ! strings .HasPrefix (stdout , BranchPrefix ) {
48- return nil , fmt .Errorf ("invalid HEAD branch: %v" , stdout )
49- }
50- 51- return & Branch {
52- Name : stdout [len (BranchPrefix ):],
53- Path : stdout ,
54- gitRepo : repo ,
55- }, nil
56- }
57- 5827func GetDefaultBranch (ctx context.Context , repoPath string ) (string , error ) {
5928 stdout , _ , err := NewCommand ("symbolic-ref" , "HEAD" ).RunStdString (ctx , & RunOpts {Dir : repoPath })
6029 if err != nil {
@@ -67,37 +36,6 @@ func GetDefaultBranch(ctx context.Context, repoPath string) (string, error) {
6736 return strings .TrimPrefix (stdout , BranchPrefix ), nil
6837}
6938
70- // GetBranch returns a branch by it's name
71- func (repo * Repository ) GetBranch (branch string ) (* Branch , error ) {
72- if ! repo .IsBranchExist (branch ) {
73- return nil , ErrBranchNotExist {branch }
74- }
75- return & Branch {
76- Path : repo .Path ,
77- Name : branch ,
78- gitRepo : repo ,
79- }, nil
80- }
81- 82- // GetBranches returns a slice of *git.Branch
83- func (repo * Repository ) GetBranches (skip , limit int ) ([]* Branch , int , error ) {
84- brs , countAll , err := repo .GetBranchNames (skip , limit )
85- if err != nil {
86- return nil , 0 , err
87- }
88- 89- branches := make ([]* Branch , len (brs ))
90- for i := range brs {
91- branches [i ] = & Branch {
92- Path : repo .Path ,
93- Name : brs [i ],
94- gitRepo : repo ,
95- }
96- }
97- 98- return branches , countAll , nil
99- }
100- 10139// DeleteBranchOptions Option(s) for delete branch
10240type DeleteBranchOptions struct {
10341 Force bool
@@ -147,11 +85,6 @@ func (repo *Repository) RemoveRemote(name string) error {
14785 return err
14886}
14987
150- // GetCommit returns the head commit of a branch
151- func (branch * Branch ) GetCommit () (* Commit , error ) {
152- return branch .gitRepo .GetBranchCommit (branch .Name )
153- }
154- 15588// RenameBranch rename a branch
15689func (repo * Repository ) RenameBranch (from , to string ) error {
15790 _ , _ , err := NewCommand ("branch" , "-m" ).AddDynamicArguments (from , to ).RunStdString (repo .Ctx , & RunOpts {Dir : repo .Path })
0 commit comments