@@ -12,7 +12,7 @@ public class OdbBackendFixture : BaseFixture
12
12
{
13
13
private const string content = "test\n " ;
14
14
15
- private static void AddCommitToRepo ( Repository repo )
15
+ private static Commit AddCommitToRepo ( Repository repo )
16
16
{
17
17
string relativeFilepath = "test.txt" ;
18
18
Touch ( repo . Info . WorkingDirectory , relativeFilepath , content ) ;
@@ -23,7 +23,7 @@ private static void AddCommitToRepo(Repository repo)
23
23
Assert . Equal ( "9daeafb9864cf43055ae93beb0afd6c7d144bfa4" , ie . Id . Sha ) ;
24
24
25
25
var author = new Signature ( "nulltoken" , "emeric.fermas@gmail.com" , DateTimeOffset . Parse ( "Wed, Dec 14 2011 08:29:03 +0100" ) ) ;
26
- repo . Commit ( "Initial commit" , author , author ) ;
26
+ var commit = repo . Commit ( "Initial commit" , author , author ) ;
27
27
28
28
relativeFilepath = "big.txt" ;
29
29
var zeros = new string ( '0' , 32 * 1024 + 3 ) ;
@@ -33,6 +33,8 @@ private static void AddCommitToRepo(Repository repo)
33
33
ie = repo . Index [ relativeFilepath ] ;
34
34
Assert . NotNull ( ie ) ;
35
35
Assert . Equal ( "6518215c4274845a759cb498998fe696c42e3e0f" , ie . Id . Sha ) ;
36
+
37
+ return commit ;
36
38
}
37
39
38
40
private static void AssertGeneratedShas ( Repository repo )
@@ -147,6 +149,34 @@ public void CanEnumerateTheContentOfTheObjectDatabase()
147
149
}
148
150
}
149
151
152
+ [ Fact ]
153
+ public void CanPushWithACustomBackend ( )
154
+ {
155
+ string remoteRepoPath = InitNewRepository ( true ) ;
156
+ string localRepoPath = InitNewRepository ( ) ;
157
+ Commit commit ;
158
+
159
+ using ( var localRepo = new Repository ( localRepoPath ) )
160
+ {
161
+ localRepo . ObjectDatabase . AddBackend ( new MockOdbBackend ( ) , 5 ) ;
162
+
163
+ commit = AddCommitToRepo ( localRepo ) ;
164
+
165
+ Remote remote = localRepo . Network . Remotes . Add ( "origin" , remoteRepoPath ) ;
166
+
167
+ localRepo . Branches . Update ( localRepo . Head ,
168
+ b => b . Remote = remote . Name ,
169
+ b => b . UpstreamBranch = localRepo . Head . CanonicalName ) ;
170
+
171
+ localRepo . Network . Push ( localRepo . Head ) ;
172
+ }
173
+
174
+ using ( var remoteRepo = new Repository ( remoteRepoPath ) )
175
+ {
176
+ Assert . Equal ( commit , remoteRepo . Head . Tip ) ;
177
+ }
178
+ }
179
+
150
180
#region MockOdbBackend
151
181
152
182
private class MockOdbBackend : OdbBackend
@@ -160,7 +190,8 @@ protected override OdbBackendOperations SupportedOperations
160
190
OdbBackendOperations . Write |
161
191
OdbBackendOperations . WriteStream |
162
192
OdbBackendOperations . Exists |
163
- OdbBackendOperations . ForEach ;
193
+ OdbBackendOperations . ForEach |
194
+ OdbBackendOperations . ReadHeader ;
164
195
}
165
196
}
166
197
@@ -270,16 +301,29 @@ public override bool Exists(ObjectId oid)
270
301
return m_objectIdToContent . ContainsKey ( oid ) ;
271
302
}
272
303
304
+ public override int ReadHeader ( ObjectId oid , out int length , out ObjectType objectType )
305
+ {
306
+ objectType = default ( ObjectType ) ;
307
+ length = 0 ;
308
+
309
+ MockGitObject gitObject ;
310
+
311
+ if ( ! m_objectIdToContent . TryGetValue ( oid , out gitObject ) )
312
+ {
313
+ return ( int ) ReturnCode . GIT_ENOTFOUND ;
314
+ }
315
+
316
+ objectType = gitObject . ObjectType ;
317
+ length = ( int ) gitObject . Length ;
318
+
319
+ return ( int ) ReturnCode . GIT_OK ;
320
+ }
321
+
273
322
private readonly Dictionary < ObjectId , MockGitObject > m_objectIdToContent =
274
323
new Dictionary < ObjectId , MockGitObject > ( ) ;
275
324
276
325
#region Unimplemented
277
326
278
- public override int ReadHeader ( ObjectId oid , out int length , out ObjectType objectType )
279
- {
280
- throw new NotImplementedException ( ) ;
281
- }
282
-
283
327
public override int ReadStream ( ObjectId oid , out OdbBacken
4370
dStream stream )
284
328
{
285
329
throw new NotImplementedException ( ) ;
0 commit comments