@@ -161,7 +161,26 @@ public void CreatingBranchWithEmptyNameThrows()
161
161
{
162
162
using ( var repo = new Repository ( Constants . TestRepoPath ) )
163
163
{
164
- Assert . Throws < ArgumentException > ( ( ) => repo . Branches . Create ( string . Empty , "not_important_sha" ) ) ;
164
+ Assert . Throws < ArgumentException > ( ( ) => repo . Branches . Create ( string . Empty , repo . Head . ResolveToDirectReference ( ) . TargetIdentifier ) ) ;
165
+ }
166
+ }
167
+
168
+ [ Test ]
169
+ [ Ignore ( "Not implemented yet." ) ]
170
+ public void CreatingBranchWithUnknownNamedTargetThrows ( )
171
+ {
172
+ using ( var repo = new Repository ( Constants . TestRepoPath ) )
173
+ {
174
+ Assert . Throws < ArgumentException > ( ( ) => repo . Branches . Create ( "my_new_branch" , "my_old_branch" ) ) ;
175
+ }
176
+ }
177
+
178
+ [ Test ]
179
+ public void CreatingBranchWithUnknownShaTargetThrows ( )
180
+ {
181
+ using ( var repo = new Repository ( Constants . TestRepoPath ) )
182
+ {
183
+ Assert . Throws < ApplicationException > ( ( ) => repo . Branches . Create ( "my_new_branch" , Constants . UnknownSha ) ) ;
165
184
}
166
185
}
167
186
@@ -179,7 +198,7 @@ public void CreatingBranchWithNullNameThrows()
179
198
{
180
199
using ( var repo = new Repository ( Constants . TestRepoPath ) )
181
200
{
182
- Assert . Throws < ArgumentNullException > ( ( ) => repo . Branches . Create ( null , "not_important_sha" ) ) ;
201
+ Assert . Throws < ArgumentNullException > ( ( ) => repo . Branches . Create ( null , repo . Head . ResolveToDirectReference ( ) . TargetIdentifier ) ) ;
183
202
}
184
203
}
185
204
@@ -260,6 +279,7 @@ public void CanMoveABranch()
260
279
repo . Branches [ "br3" ] . ShouldNotBeNull ( ) ;
261
280
}
262
281
}
282
+
263
283
[ Test ]
264
284
public void BlindlyMovingABranchOverAnExistingOneThrows ( )
265
285
{
@@ -294,5 +314,23 @@ public void CanMoveABranchWhileOverwritingAnExistingOne()
294
314
newTest . Tip . ShouldEqual ( br2 . Tip ) ;
295
315
}
296
316
}
317
+
318
+ [ Test ]
319
+ public void CreatingABranchTriggersTheCreationOfADirectReference ( )
320
+ {
321
+ using ( var path = new TemporaryCloneOfTestRepo ( ) )
322
+ using ( var repo = new Repository ( path . RepositoryPath ) )
323
+ {
324
+ var newBranch = repo . CreateBranch ( "clone-of-master" ) ;
325
+ newBranch . IsCurrentRepositoryHead . ShouldBeFalse ( ) ;
326
+
327
+ var commitId = repo . Head . ResolveToDirectReference ( ) . TargetIdentifier ;
328
+ newBranch . Tip . Sha . ShouldEqual ( commitId ) ;
329
+
330
+ var reference = repo . Refs [ newBranch . CanonicalName ] ;
B222
331
+ reference . ShouldNotBeNull ( ) ;
332
+ Assert . IsInstanceOf ( typeof ( DirectReference ) , reference ) ;
333
+ }
334
+ }
297
335
}
298
- }
336
+ }
0 commit comments