@@ -163,6 +163,18 @@ func (pushService *pushService) createRepository() (*github.Repository, error) {
163163 return repository , nil
164164}
165165
166+ func splitLargeRefSpecs (refSpecs []config.RefSpec ) [][]config.RefSpec {
167+ splitRefSpecs := [][]config.RefSpec {}
168+ for i := 0 ; i < len (refSpecs ); i += 25 {
169+ end := i + 100
170+ if end > len (refSpecs ) {
171+ end = len (refSpecs )
172+ }
173+ splitRefSpecs = append (splitRefSpecs , refSpecs [i :end ])
174+ }
175+ return splitRefSpecs
176+ }
177+
166178func (pushService * pushService ) pushGit (repository * github.Repository , initialPush bool ) error {
167179 remoteURL := pushService .gitURL
168180 if remoteURL == "" {
@@ -210,9 +222,10 @@ func (pushService *pushService) pushGit(repository *github.Repository, initialPu
210222 deleteRefSpecs = append (deleteRefSpecs , config .RefSpec (":" + remoteReference .Name ().String ()))
211223 }
212224 }
213- refSpecBatches = append (refSpecBatches , deleteRefSpecs )
225+ refSpecBatches = append (refSpecBatches , splitLargeRefSpecs ( deleteRefSpecs ) ... )
214226
215- defaultBranchRefSpec := "+refs/heads/main:refs/heads/main"
227+ defaultBranchRef := "refs/heads/main"
228+ defaultBranchRefSpec := "+" + defaultBranchRef + ":" + defaultBranchRef
216229 if initialPush {
217230 releasePathStats , err := ioutil .ReadDir (pushService .cacheDirectory .ReleasesPath ())
218231 if err != nil {
@@ -227,20 +240,30 @@ func (pushService *pushService) pushGit(repository *github.Repository, initialPu
227240 }
228241 initialRefSpecs = append (initialRefSpecs , config .RefSpec ("+" + tagReferenceName .String ()+ ":" + tagReferenceName .String ()))
229242 }
230- refSpecBatches = append (refSpecBatches , initialRefSpecs )
243+ refSpecBatches = append (refSpecBatches , splitLargeRefSpecs ( initialRefSpecs ) ... )
231244 } else {
232245 // We've got to push the default branch on its own, so that it will be made the default branch if the repository has just been created. We then push everything else afterwards.
233246 refSpecBatches = append (refSpecBatches ,
234247 []config.RefSpec {
235248 config .RefSpec (defaultBranchRefSpec ),
236249 },
237- []config.RefSpec {
238- config .RefSpec ("+refs/*:refs/*" ),
239- },
240250 )
251+ nonDefaultRefSpecs := []config.RefSpec {}
252+ localReferences , err := gitRepository .References ()
253+ if err != nil {
254+ return errors .Wrap (err , "Error listing local references." )
255+ }
256+ localReferences .ForEach (func (ref * plumbing.Reference ) error {
257+ if ref .Name ().String () != defaultBranchRef && strings .HasPrefix (ref .Name ().String (), "refs/" ) {
258+ nonDefaultRefSpecs = append (nonDefaultRefSpecs , config .RefSpec ("+" + ref .Name ().String ()+ ":" + ref .Name ().String ()))
259+ }
260+ return nil
261+ })
262+ refSpecBatches = append (refSpecBatches , splitLargeRefSpecs (nonDefaultRefSpecs )... )
241263 }
242264 for _ , refSpecs := range refSpecBatches {
243265 if len (refSpecs ) != 0 {
266+ log .Debugf ("Pushing refspecs %s." , refSpecs )
244267 err = remote .PushContext (pushService .ctx , & git.PushOptions {
245268 RefSpecs : refSpecs ,
246269 Auth : credentials ,
@@ -393,17 +416,17 @@ func (pushService *pushService) pushReleases() error {
393416 existingAssets = append (existingAssets , assets ... )
394417 }
395418
396- assetsPath := pushService .cacheDirectory .AssetsPath (releaseName )
397- assetPathStats , err := ioutil .ReadDir (assetsPath )
419+ // assetsPath := pushService.cacheDirectory.AssetsPath(releaseName)
420+ // assetPathStats, err := ioutil.ReadDir(assetsPath)
398421 if err != nil {
399422 return errors .Wrap (err , "Error reading release assets." )
400423 }
401- for _ , assetPathStat := range assetPathStats {
402- err := pushService .createOrUpdateReleaseAsset (release , existingAssets , assetPathStat )
403- if err != nil {
404- return err
405- }
406- }
424+ // for _, assetPathStat := range assetPathStats {
425+ // err := pushService.createOrUpdateReleaseAsset(release, existingAssets, assetPathStat)
426+ // if err != nil {
427+ // return err
428+ // }
429+ // }
407430 }
408431
409432 return nil
0 commit comments