@@ -182,6 +182,7 @@ def _from_string(cls, repo, line):
182182 # obj.size = object_size
183183 # return cls(repo, full_path, obj)
184184
185+
185186
186187class SymbolicReference (object ):
187188 """
@@ -384,12 +385,80 @@ class Head(Reference):
384385 """
385386 _common_path_default = "refs/heads"
386387
388+ @classmethod
389+ def create (cls , repo , path , commit = HEAD (), ** kwargs ):
390+ """
391+ Create a new head.
392+ ``repo``
393+ Repository to create the head in
394+
395+ ``path``
396+ The name or path of the head, i.e. 'new_branch' or
397+ feature/feature1. The prefix refs/heads is implied.
398+
399+ ``commit``
400+ Commit to which the new head should point, defaults to the
401+ current HEAD
402+
403+ ``**kwargs``
404+ 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.
407+
408+ Returns
409+ Newly created Head
410+
411+ Note
412+ This does not alter the current HEAD, index or Working Tree
413+ """
414+ raise NotImplementedError ("todo" )
415+
416+
417+ @classmethod
418+ def delete (cls , repo , * heads , force = False ):
419+ """
420+ Delete the given heads
421+
422+ ``force``
423+ If True, the heads will be deleted even if they are not yet merged into
424+ the main development stream
425+ """
426+ flag = "-d"
427+ if force :
428+ flag = "-D"
429+ repo .git .branch (flag , * heads )
430+
431+
432+ def rename (self , new_path , force = False ):
433+ """
434+ Rename self to a new path
435+
436+ ``new_path``
437+ Either a simple name or a path, i.e. new_name or features/new_name.
438+ The prefix refs/heads is implied
439+
440+ ``force``
441+ If True, the rename will succeed even if a head with the target name
442+ already exists.
443+
444+ Returns
445+ self
446+ """
447+ flag = "-m"
448+ if force :
449+ flag = "-M"
450+
451+ self .repo .git .branch (flag , new_path )
452+ self .path = "%s/%s" % (self ._common_path_default , new_path )
453+ return self
454+
455+
387456
388457class TagReference (Reference ):
389458 """
390459 Class representing a lightweight tag reference which either points to a commit
391- or to a tag object. In the latter case additional information, like the signature
392- or the tag-creator, is available.
460+ , a tag object or any other object . In the latter case additional information,
461+ like the signature or the tag-creator, is available.
393462
394463 This tag object will always point to a commit object, but may carray additional
395464 information in a tag object::
@@ -427,6 +496,43 @@ def tag(self):
427496 if self .object .type == "tag" :
428497 return self .object
429498 return None
499+
500+ @classmethod
501+ def create (cls , repo , path , ref , message = None , ** kwargs ):
502+ """
503+ Create a new tag object.
504+
505+ ``path``
506+ The name of the tag, i.e. 1.0 or releases/1.0.
507+ The prefix refs/tags is implied
508+
509+ ``ref``
510+ A reference to the object you want to tag. It can be a commit, tree or
511+ blob.
512+
513+ ``message``
514+ If not None, the message will be used in your tag object. This will also
515+ create an additional tag object that allows to obtain that information, i.e.::
516+ tagref.tag.message
517+
518+ ``**kwargs``
519+ Additional keyword arguments to be passed to git-tag, i.e. f to force creation
520+ of a tag.
521+
522+ Returns
523+ A new TagReference
524+ """
525+ raise NotImplementedError ("todo" )
526+
527+ @classmethod
528+ def delete (cls , repo , * tags ):
529+ """
530+ Delete the given existing tag or tags
531+ """
532+ repo .git .tag ("-d" , * tags )
533+
534+
535+
430536
431537
432538# provide an alias
@@ -460,3 +566,10 @@ def remote_branch(self):
460566 """
461567 tokens = self .path .split ('/' )
462568 return '/' .join (tokens [3 :])
569+
570+ @classmethod
571+ def delete (cls , repo , * remotes ):
572+ """
573+ Delete the given remote references.
574+ """
575+ repo .git .branch ("-d" , "-r" , * remotes )
0 commit comments