@@ -7,7 +7,6 @@ package git
7
7
import (
8
8
"context"
9
9
"errors"
10
- "fmt"
11
10
"strings"
12
11
)
13
12
@@ -25,36 +24,6 @@ func IsBranchExist(ctx context.Context, repoPath, name string) bool {
25
24
return IsReferenceExist (ctx , repoPath , BranchPrefix + name )
26
25
}
27
26
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
-
58
27
func GetDefaultBranch (ctx context.Context , repoPath string ) (string , error ) {
59
28
stdout , _ , err := NewCommand ("symbolic-ref" , "HEAD" ).RunStdString (ctx , & RunOpts {Dir : repoPath })
60
29
if err != nil {
@@ -67,37 +36,6 @@ func GetDefaultBranch(ctx context.Context, repoPath string) (string, error) {
67
36
return strings .TrimPrefix (stdout , BranchPrefix ), nil
68
37
}
69
38
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
-
101
39
// DeleteBranchOptions Option(s) for delete branch
102
40
type DeleteBranchOptions struct {
103
41
Force bool
@@ -147,11 +85,6 @@ func (repo *Repository) RemoveRemote(name string) error {
147
85
return err
148
86
}
149
87
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
-
155
88
// RenameBranch rename a branch
156
89
func (repo * Repository ) RenameBranch (from , to string ) error {
157
90
_ , _ , err := NewCommand ("branch" , "-m" ).AddDynamicArguments (from , to ).RunStdString (repo .Ctx , & RunOpts {Dir : repo .Path })
0 commit comments