@@ -5,12 +5,16 @@ import (
5
5
"context"
6
6
"errors"
7
7
"io"
8
+ "io/ioutil"
9
+ "os"
10
+ "path/filepath"
8
11
"runtime"
9
12
"time"
10
13
11
14
"github.com/go-git/go-git/v5/config"
12
15
"github.com/go-git/go-git/v5/plumbing"
13
16
"github.com/go-git/go-git/v5/plumbing/cache"
17
+ "github.com/go-git/go-git/v5/plumbing/object"
14
18
"github.com/go-git/go-git/v5/plumbing/protocol/packp"
15
19
"github.com/go-git/go-git/v5/plumbing/protocol/packp/capability"
16
20
"github.com/go-git/go-git/v5/plumbing/storer"
@@ -1206,3 +1210,91 @@ func (s *RemoteSuite) TestPushRequireRemoteRefs(c *C) {
1206
1210
c .Assert (err , IsNil )
1207
1211
c .Assert (newRef , Not (DeepEquals ), oldRef )
1208
1212
}
1213
+
1214
+ func (s * RemoteSuite ) TestCanPushShasToReference (c * C ) {
1215
+ d , err := ioutil .TempDir ("" , "TestCanPushShasToReference" )
1216
+ c .Assert (err , IsNil )
1217
+ if err != nil {
1218
+ return
1219
+ }
1220
+ defer os .RemoveAll (d )
1221
+
1222
+ // remote currently forces a plain path for path based remotes inside the PushContext function.
1223
+ // This makes it impossible, in the current state to use memfs.
1224
+ // For the sake of readability, use the same osFS everywhere and use plain git repositories on temporary files
1225
+ remote , err := PlainInit (filepath .Join (d , "remote" ), true )
1226
+ c .Assert (err , IsNil )
1227
+ c .Assert (remote , NotNil )
1228
+
1229
+ repo , err := PlainInit (filepath .Join (d , "repo" ), false )
1230
+ c .Assert (err , IsNil )
1231
+ c .Assert (repo , NotNil )
1232
+
1233
+ fd , err := os .Create (filepath .Join (d , "repo" , "README.md" ))
1234
+ c .Assert (err , IsNil )
1235
+ if err != nil {
1236
+ return
1237
+ }
1238
+ _ , err = fd .WriteString ("# test repo" )
1239
+ c .Assert (err , IsNil )
1240
+ if err != nil {
1241
+ return
1242
+ }
1243
+ err = fd .Close ()
1244
+ c .Assert (err , IsNil )
1245
+ if err != nil {
1246
+ return
1247
+ }
1248
+
1249
+ wt , err := repo .Worktree ()
1250
+ c .Assert (err , IsNil )
1251
+ if err != nil {
1252
+ return
1253
+ }
1254
+
1255
+ wt .Add ("README.md" )
1256
+ sha , err := wt .Commit ("test commit" , & CommitOptions {
1257
+ Author : & object.Signature {
1258
+ Name : "test" ,
1259
+
1260
+ When : time .Now (),
1261
+ },
1262
+ Committer : & object.Signature {
1263
+ Name : "test" ,
1264
+
1265
+ When : time .Now (),
1266
+ },
1267
+ })
1268
+ c .Assert (err , IsNil )
1269
+ if err != nil {
1270
+ return
1271
+ }
1272
+
1273
+ gitremote , err := repo .CreateRemote (& config.RemoteConfig {
1274
+ Name : "local" ,
1275
+ URLs : []string {filepath .Join (d , "remote" )},
1276
+ })
1277
+ c .Assert (err , IsNil )
1278
+ if err != nil {
1279
+ return
1280
+ }
1281
+
1282
+ err = gitremote .Push (& PushOptions {
1283
+ RemoteName : "local" ,
1284
+ RefSpecs : []config.RefSpec {
1285
+ // TODO: check with short hashes that this is still respected
1286
+ config .RefSpec (sha .String () + ":refs/heads/branch" ),
1287
+ },
1288
+ })
1289
+ c .Assert (err , IsNil )
1290
+ if err != nil {
1291
+ return
1292
+ }
1293
+
1294
+ ref , err := remote .Reference (plumbing .ReferenceName ("refs/heads/branch" ), false )
1295
+ c .Assert (err , IsNil )
1296
+ if err != nil {
1297
+ return
1298
+ }
1299
+ c .Assert (ref .Hash ().String (), Equals , sha .String ())
1300
+ }
0 commit comments