@@ -10,6 +10,7 @@ import (
10
10
11
11
"github.com/go-git/go-billy/v5/osfs"
12
12
"github.com/go-git/go-git/v5/config"
13
+ "github.com/go-git/go-git/v5/internal/url"
13
14
"github.com/go-git/go-git/v5/plumbing"
14
15
"github.com/go-git/go-git/v5/plumbing/cache"
15
16
"github.com/go-git/go-git/v5/plumbing/format/packfile"
@@ -104,7 +105,11 @@ func (r *Remote) PushContext(ctx context.Context, o *PushOptions) (err error) {
104
105
return fmt .Errorf ("remote names don't match: %s != %s" , o .RemoteName , r .c .Name )
105
106
}
106
107
107
- s , err := newSendPackSession (r .c .URLs [0 ], o .Auth , o .InsecureSkipTLS , o .CABundle )
108
+ if o .RemoteURL == "" {
109
+ o .RemoteURL = r .c .URLs [0 ]
110
+ }
111
+
112
+ s , err := newSendPackSession (o .RemoteURL , o .Auth , o .InsecureSkipTLS , o .CABundle )
108
113
if err != nil {
109
114
return err
110
115
}
@@ -184,12 +189,12 @@ func (r *Remote) PushContext(ctx context.Context, o *PushOptions) (err error) {
184
189
var hashesToPush []plumbing.Hash
185
190
// Avoid the expensive revlist operation if we're only doing deletes.
186
191
if ! allDelete {
187
- if r . c . IsFirstURLLocal ( ) {
192
+ if url . IsLocalEndpoint ( o . RemoteURL ) {
188
193
// If we're are pushing to a local repo, it might be much
189
194
// faster to use a local storage layer to get the commits
190
195
// to ignore, when calculating the object revlist.
191
196
localStorer := filesystem .NewStorage (
192
- osfs .New (r . c . URLs [ 0 ] ), cache .NewObjectLRUDefault ())
197
+ osfs .New (o . RemoteURL ), cache .NewObjectLRUDefault ())
193
198
hashesToPush , err = revlist .ObjectsWithStorageForIgnores (
194
199
r .s , localStorer , objects , haves )
195
200
} else {
@@ -392,7 +397,11 @@ func (r *Remote) fetch(ctx context.Context, o *FetchOptions) (sto storer.Referen
392
397
o .RefSpecs = r .c .Fetch
393
398
}
394
399
395
- s , err := newUploadPackSession (r .c .URLs [0 ], o .Auth , o .InsecureSkipTLS , o .CABundle )
400
+ if o .RemoteURL == "" {
401
+ o .RemoteURL = r .c .URLs [0 ]
402
+ }
403
+
404
+ s , err := newUploadPackSession (o .RemoteURL , o .Auth , o .InsecureSkipTLS , o .CABundle )
396
405
if err != nil {
397
406
return nil , err
398
407
}
0 commit comments