@@ -25,31 +25,22 @@ func IsBranchExist(ctx context.Context, repoPath, name string) bool {
25
25
return IsReferenceExist (ctx , repoPath , BranchPrefix + name )
26
26
}
27
27
28
- // Branch represents a Git branch.
29
- type Branch struct {
30
- Name string
31
- Path string
32
- }
33
-
34
28
// GetHEADBranch returns corresponding branch of HEAD.
35
- func (repo * Repository ) GetHEADBranch () (* Branch , error ) {
29
+ func (repo * Repository ) GetHEADBranch () (string , error ) {
36
30
if repo == nil {
37
- return nil , fmt .Errorf ("nil repo" )
31
+ return "" , fmt .Errorf ("nil repo" )
38
32
}
39
33
stdout , _ , err := NewCommand ("symbolic-ref" , "HEAD" ).RunStdString (repo .Ctx , & RunOpts {Dir : repo .Path })
40
34
if err != nil {
41
- return nil , err
35
+ return "" , err
42
36
}
43
37
stdout = strings .TrimSpace (stdout )
44
38
45
39
if ! strings .HasPrefix (stdout , BranchPrefix ) {
46
- return nil , fmt .Errorf ("invalid HEAD branch: %v" , stdout )
40
+ return "" , fmt .Errorf ("invalid HEAD branch: %v" , stdout )
47
41
}
48
42
49
- return & Branch {
50
- Name : stdout [len (BranchPrefix ):],
51
- Path : stdout ,
52
- }, nil
43
+ return stdout [len (BranchPrefix ):], nil
53
44
}
54
45
55
46
func GetDefaultBranch (ctx context.Context , repoPath string ) (string , error ) {
@@ -65,32 +56,11 @@ func GetDefaultBranch(ctx context.Context, repoPath string) (string, error) {
65
56
}
66
57
67
58
// GetBranch returns a branch by it's name
68
- func (repo * Repository ) GetBranch (branch string ) (* Branch , error ) {
59
+ func (repo * Repository ) GetBranch (branch string ) (string , error ) {
69
60
if ! repo .IsBranchExist (branch ) {
70
- return nil , ErrBranchNotExist {branch }
71
- }
72
- return & Branch {
73
- Path : repo .Path ,
74
- Name : branch ,
75
- }, nil
76
- }
77
-
78
- // GetBranches returns a slice of *git.Branch
79
- func (repo * Repository ) GetBranches (skip , limit int ) ([]* Branch , int , error ) {
80
- brs , countAll , err := repo .GetBranchNames (skip , limit )
81
- if err != nil {
82
- return nil , 0 , err
61
+ return "" , ErrBranchNotExist {branch }
83
62
}
84
-
85
- branches := make ([]* Branch , len (brs ))
86
- for i := range brs {
87
- branches [i ] = & Branch {
88
- Path : repo .Path ,
89
- Name : brs [i ],
90
- }
91
- }
92
-
93
- return branches , countAll , nil
63
+ return branch , nil
94
64
}
95
65
96
66
// DeleteBranchOptions Option(s) for delete branch
0 commit comments