@@ -19,7 +19,7 @@ class Reference(LazyMixin, Iterable):
1919 _common_path_default = "refs"
2020 _id_attribute_ = "name"
2121
22- def __init__ (self , repo , path , object = None ):
22+ def __init__ (self , repo , path ):
2323 """
2424 Initialize this instance
2525 ``repo``
@@ -29,16 +29,12 @@ def __init__(self, repo, path, object = None):
2929 Path relative to the .git/ directory pointing to the ref in question, i.e.
3030 refs/heads/master
3131
32- ``object``
33- Object instance, will be retrieved on demand if None
3432 """
3533 if not path .startswith (self ._common_path_default ):
3634 raise ValueError ("Cannot instantiate %s Reference from path %s" % ( self .__class__ .__name__ , path ))
3735
3836 self .repo = repo
3937 self .path = path
40- if object is not None :
41- self .object = object
4238
4339 def __str__ (self ):
4440 return self .name
@@ -386,7 +382,7 @@ class Head(Reference):
386382 _common_path_default = "refs/heads"
387383
388384 @classmethod
389- def create (cls , repo , path , commit = HEAD () , ** kwargs ):
385+ def create (cls , repo , path , commit = ' HEAD' , force = False , ** kwargs ):
390386 """
391387 Create a new head.
392388 ``repo``
@@ -399,30 +395,42 @@ def create(cls, repo, path, commit=HEAD(), **kwargs ):
399395 ``commit``
400396 Commit to which the new head should point, defaults to the
401397 current HEAD
398+
399+ ``force``
400+ if True, force creation even if branch with that name already exists.
402401
403402 ``**kwargs``
404403 Additional keyword arguments to be passed to git-branch, i.e.
405- track, no-track, l, f to force creation even if branch with that
406- name already exists.
404+ track, no-track, l
407405
408406 Returns
409407 Newly created Head
410408
411409 Note
412410 This does not alter the current HEAD, index or Working Tree
413411 """
414- raise NotImplementedError ("todo" )
412+ if cls is not Head :
413+ raise TypeError ("Only Heads can be created explicitly, not objects of type %s" % cls .__name__ )
414+
415+ args = ( path , commit )
416+ if force :
417+ kwargs ['f' ] = True
418+
419+ repo .git .branch (* args , ** kwargs )
420+ return cls (repo , "%s/%s" % ( cls ._common_path_default , path ))
415421
416422
417423 @classmethod
418- def delete (cls , repo , * heads , force = False ):
424+ def delete (cls , repo , * heads , ** kwargs ):
419425 """
420426 Delete the given heads
421427
422428 ``force``
423429 If True, the heads will be deleted even if they are not yet merged into
424- the main development stream
430+ the main development stream.
431+ Default False
425432 """
433+ force = kwargs .get ("force" , False )
426434 flag = "-d"
427435 if force :
428436 flag = "-D"
@@ -448,7 +456,7 @@ def rename(self, new_path, force=False):
448456 if force :
449457 flag = "-M"
450458
451- self .repo .git .branch (flag , new_path )
459+ self .repo .git .branch (flag , self , new_path )
452460 self .path = "%s/%s" % (self ._common_path_default , new_path )
453461 return self
454462
@@ -568,7 +576,7 @@ def remote_branch(self):
568576 return '/' .join (tokens [3 :])
569577
570578 @classmethod
571- def delete (cls , repo , * remotes ):
579+ def delete (cls , repo , * remotes , ** kwargs ):
572580 """
573581 Delete the given remote references.
574582 """
0 commit comments