@@ -53,6 +53,7 @@ func (r Repo) Clone(pluginURL, ref string) error {
53
53
var stdErr strings.Builder
54
54
cmd .Stdout = & stdOut
55
55
cmd .Stderr = & stdErr
56
+
56
57
err := cmd .Run ()
57
58
58
59
if err != nil {
@@ -92,30 +93,6 @@ func (r Repo) RemoteURL() (string, error) {
92
93
return remotes [0 ].Config ().URLs [0 ], nil
93
94
}
94
95
95
- func (r Repo ) RemoteDefaultBranch () (string , error ) {
96
- // @jiminychris - https://github.com/go-git/go-git/issues/510#issuecomment-2560116147
97
- repo , err := gitOpen (r .Directory )
98
- if err != nil {
99
- return "" , err
100
- }
101
-
102
- // Get the remote you want to find the default for
103
- remote , err := repo .Remote ("origin" )
104
- if err != nil {
105
- return "" , err
106
- }
107
-
108
- references , _ := remote .List (& git.ListOptions {})
109
- // Search through the list of references in that remote for a symbolic reference named HEAD;
110
- // Its target should be the default branch name.
111
- for _ , reference := range references {
112
- if reference .Name () == "HEAD" && reference .Type () == plumbing .SymbolicReference {
113
- return reference .Target ().String (), nil
114
- }
115
- }
116
- return "" , fmt .Errorf ("unable to find default branch for git directory %s" , r .Directory )
117
- }
118
-
119
96
// Update updates the plugin's Git repository to the ref if provided, or the
120
97
// latest commit on the current branch
121
98
func (r Repo ) Update (ref string ) (string , string , string , error ) {
@@ -131,7 +108,7 @@ func (r Repo) Update(ref string) (string, string, string, error) {
131
108
132
109
// If no ref is provided we take the default branch of the remote
133
110
if strings .TrimSpace (ref ) == "" {
134
- ref , err = r .RemoteDefaultBranch ()
111
+ ref , err = r .remoteDefaultBranch ()
135
112
if err != nil {
136
113
return "" , "" , "" , err
137
114
}
@@ -167,6 +144,30 @@ func (r Repo) Update(ref string) (string, string, string, error) {
167
144
return ref , oldHash .String (), newHash .Hash ().String (), nil
168
145
}
169
146
147
+ func (r Repo ) remoteDefaultBranch () (string , error ) {
148
+ // @jiminychris - https://github.com/go-git/go-git/issues/510#issuecomment-2560116147
149
+ repo , err := gitOpen (r .Directory )
150
+ if err != nil {
151
+ return "" , err
152
+ }
153
+
154
+ // Get the remote you want to find the default for
155
+ remote , err := repo .Remote ("origin" )
156
+ if err != nil {
157
+ return "" , err
158
+ }
159
+
160
+ references , _ := remote .List (& git.ListOptions {})
161
+ // Search through the list of references in that remote for a symbolic reference named HEAD;
162
+ // Its target should be the default branch name.
163
+ for _ , reference := range references {
164
+ if reference .Name () == "HEAD" && reference .Type () == plumbing .SymbolicReference {
165
+ return reference .Target ().String (), nil
166
+ }
167
+ }
168
+ return "" , fmt .Errorf ("unable to find default branch for git directory %s" , r .Directory )
169
+ }
170
+
170
171
func stdErrToErrMsg (stdErr string ) string {
171
172
lines := strings .Split (strings .TrimSuffix (stdErr , "\n " ), "\n " )
172
173
return lines [len (lines )- 1 ]
0 commit comments