summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--TODO4
-rw-r--r--lib/git/refs.py4
-rw-r--r--lib/git/repo.py55
-rw-r--r--test/git/test_repo.py12
4 files changed, 69 insertions, 6 deletions
diff --git a/TODO b/TODO
index 147eb02d..e77ba340 100644
--- a/TODO
+++ b/TODO
@@ -106,8 +106,6 @@ Remote
------
* iter_items should parse the configuration file manually - currently a command
is issued which is much slower than it has to be ( compared to manual parsing )
-* Creation and deletion methods for references should be part of the interface, allowing
- repo.create_head(...) instaed of Head.create(repo, ...). Its a convenience thing, clearly
* When parsing fetch-info, the regex will not allow spaces in the target remote ref as
I couldn't properly parse the optional space separated note in that case. Probably
the regex should be improved to handle this gracefully.
@@ -118,8 +116,6 @@ Repo
currently regex are used a lot although we can deduct what will be next.
- Read data from a stream directly from git command
* Figure out how to implement a proper merge API
-* There should be a way to create refs and delete them, instead of having to use
- the awkward Head.create( repo, ... ) way
* repo.checkout should be added that does everything HEAD.reset does, but in addition
it allows to checkout heads beforehand, hence its more like a repo.head.reference = other_head.
diff --git a/lib/git/refs.py b/lib/git/refs.py
index cea3e720..ddf98fc7 100644
--- a/lib/git/refs.py
+++ b/lib/git/refs.py
@@ -434,7 +434,7 @@ class Head(Reference):
_common_path_default = "refs/heads"
@classmethod
- def create(cls, repo, path, commit='HEAD', force=False, **kwargs ):
+ def create(cls, repo, path, commit='HEAD', force=False, **kwargs ):
"""
Create a new head.
``repo``
@@ -560,7 +560,7 @@ class TagReference(Reference):
@classmethod
def create(cls, repo, path, ref='HEAD', message=None, force=False, **kwargs):
"""
- Create a new tag object.
+ Create a new tag reference.
``path``
The name of the tag, i.e. 1.0 or releases/1.0.
diff --git a/lib/git/repo.py b/lib/git/repo.py
index 52469e04..9c3db055 100644
--- a/lib/git/repo.py
+++ b/lib/git/repo.py
@@ -213,6 +213,61 @@ class Repo(object):
"""
return TagReference(self, path)
+ def create_head(self, path, commit='HEAD', force=False, **kwargs ):
+ """
+ Create a new head within the repository.
+
+ For more documentation, please see the Head.create method.
+
+ Returns
+ newly created Head Reference
+ """
+ return Head.create(self, path, commit, force, **kwargs)
+
+ def delete_head(self, *heads, **kwargs):
+ """
+ Delete the given heads
+
+ ``kwargs``
+ Additional keyword arguments to be passed to git-branch
+ """
+ return Head.delete(self, *heads, **kwargs)
+
+ def create_tag(self, path, ref='HEAD', message=None, force=False, **kwargs):
+ """
+ Create a new tag reference.
+
+ For more documentation, please see the TagReference.create method.
+
+ Returns
+ TagReference object
+ """
+ return TagReference.create(self, path, ref, message, force, **kwargs)
+
+ def delete_tag(self, *tags):
+ """
+ Delete the given tag references
+ """
+ return TagReference.delete(self, *tags)
+
+ def create_remote(self, name, url, **kwargs):
+ """
+ Create a new remote.
+
+ For more information, please see the documentation of the Remote.create
+ methods
+
+ Returns
+ Remote reference
+ """
+ return Remote.create(self, name, url, **kwargs)
+
+ def delete_remote(self, remote):
+ """
+ Delete the given remote.
+ """
+ return Remote.remove(self, remote)
+
def _get_config_path(self, config_level ):
# we do not support an absolute path of the gitconfig on windows ,
# use the global config instead
diff --git a/test/git/test_repo.py b/test/git/test_repo.py
index 464cb43f..146cff1a 100644
--- a/test/git/test_repo.py
+++ b/test/git/test_repo.py
@@ -251,3 +251,15 @@ class TestRepo(TestBase):
# have no permissions
pass
# END for each config level
+
+ def test_creation_deletion(self):
+ # just a very quick test to assure it generally works. There are
+ # specialized cases in the test_refs module
+ head = self.rorepo.create_head("new_head", "HEAD~1")
+ self.rorepo.delete_head(head)
+
+ tag = self.rorepo.create_tag("new_tag", "HEAD~2")
+ self.rorepo.delete_tag(tag)
+
+ remote = self.rorepo.create_remote("new_remote", "git@server:repo.git")
+ self.rorepo.delete_remote(remote)