@@ -42,46 +42,53 @@ func GetBranchList(repo *git.Repository, branchChan chan Branch) {
42
42
splitCurrentBranch := strings .Split (currentBranch , "/" )
43
43
currentBranch = splitCurrentBranch [len (splitCurrentBranch )- 1 ]
44
44
45
- bIter , _ := repo .Branches ()
46
-
47
45
ref , _ := repo .References ()
48
- _ = ref .ForEach (func (reference * plumbing.Reference ) error {
49
- var (
50
- refNamePtr * string
51
- )
52
46
53
- if ref != nil {
54
- if reference .Name ().String () != "HEAD" && strings .Contains (reference .Name ().String (), "refs/" ) {
55
- refNameSplit := strings .Split (reference .Name ().String (), "refs/" )
56
- if len (refNameSplit ) == 2 {
57
- logger .Log (fmt .Sprintf ("Available Branch : %v" , refNameSplit [1 ]), global .StatusInfo )
58
- if strings .Contains (refNameSplit [1 ], "heads/" ) {
59
- headBranch := strings .Split (refNameSplit [1 ], "heads/" )[1 ]
60
- refNamePtr = & headBranch
61
- } else {
62
- refNamePtr = & refNameSplit [1 ]
47
+ if ref != nil {
48
+ _ = ref .ForEach (func (reference * plumbing.Reference ) error {
49
+ var (
50
+ refNamePtr * string
51
+ )
52
+ if ref != nil {
53
+ if reference .Name ().String () != "HEAD" && strings .Contains (reference .Name ().String (), "refs/" ) {
54
+ refNameSplit := strings .Split (reference .Name ().String (), "refs/" )
55
+ if len (refNameSplit ) == 2 {
56
+ logger .Log (fmt .Sprintf ("Available Branch : %v" , refNameSplit [1 ]), global .StatusInfo )
57
+ if strings .Contains (refNameSplit [1 ], "heads/" ) {
58
+ headBranch := strings .Split (refNameSplit [1 ], "heads/" )[1 ]
59
+ refNamePtr = & headBranch
60
+ } else {
61
+ refNamePtr = & refNameSplit [1 ]
62
+ }
63
+ allBranchList = append (allBranchList , refNamePtr )
63
64
}
64
- allBranchList = append (allBranchList , refNamePtr )
65
65
}
66
66
}
67
- }
67
+ return nil
68
+ })
69
+ } else {
70
+ logger .Log ("No references found!" , global .StatusError )
71
+ }
68
72
69
- return nil
70
- })
73
+ bIter , _ := repo .Branches ()
71
74
72
- _ = bIter .ForEach (func (reference * plumbing.Reference ) error {
73
- if reference != nil {
74
- localBranch := reference .String ()
75
- splitBranch := strings .Split (localBranch , "/" )
76
- localBranch = splitBranch [len (splitBranch )- 1 ]
75
+ if bIter != nil {
76
+ _ = bIter .ForEach (func (reference * plumbing.Reference ) error {
77
+ if reference != nil {
78
+ localBranch := reference .String ()
79
+ splitBranch := strings .Split (localBranch , "/" )
80
+ localBranch = splitBranch [len (splitBranch )- 1 ]
77
81
78
- branches = append (branches , & localBranch )
79
- return nil
80
- } else {
81
- return types.Error {Msg : "Empty reference" }
82
- }
83
- })
84
- bIter .Close ()
82
+ branches = append (branches , & localBranch )
83
+ return nil
84
+ } else {
85
+ return types.Error {Msg : "Empty reference" }
86
+ }
87
+ })
88
+ bIter .Close ()
89
+ } else {
90
+ logger .Log ("Nil branch reference found" , global .StatusError )
91
+ }
85
92
}
86
93
87
94
branchChan <- Branch {
0 commit comments