diff options
-rw-r--r-- | lib/git/refs.py | 21 | ||||
-rw-r--r-- | test/git/test_refs.py | 43 |
2 files changed, 57 insertions, 7 deletions
diff --git a/lib/git/refs.py b/lib/git/refs.py index 7b58f215..0efee52e 100644 --- a/lib/git/refs.py +++ b/lib/git/refs.py @@ -506,7 +506,7 @@ class TagReference(Reference): return None @classmethod - def create(cls, repo, path, ref, message=None, **kwargs): + def create(cls, repo, path, ref='HEAD', message=None, force=False, **kwargs): """ Create a new tag object. @@ -523,14 +523,23 @@ class TagReference(Reference): create an additional tag object that allows to obtain that information, i.e.:: tagref.tag.message + ``force`` + If True, to force creation of a tag even though that tag already exists. + ``**kwargs`` - Additional keyword arguments to be passed to git-tag, i.e. f to force creation - of a tag. + Additional keyword arguments to be passed to git-tag Returns A new TagReference """ - raise NotImplementedError("todo") + args = ( path, ref ) + if message: + kwargs['m'] = message + if force: + kwargs['f'] = True + + repo.git.tag(*args, **kwargs) + return TagReference(repo, "%s/%s" % (cls._common_path_default, path)) @classmethod def delete(cls, repo, *tags): @@ -579,5 +588,9 @@ class RemoteReference(Head): def delete(cls, repo, *remotes, **kwargs): """ Delete the given remote references. + + Note + kwargs are given for compatability with the base class method as we + should not narrow the signature. """ repo.git.branch("-d", "-r", *remotes) diff --git a/test/git/test_refs.py b/test/git/test_refs.py index ac213384..88e8a21a 100644 --- a/test/git/test_refs.py +++ b/test/git/test_refs.py @@ -142,6 +142,43 @@ class TestRefs(TestBase): # END for each new head name self.failUnlessRaises(TypeError, RemoteReference.create, rw_repo, "some_name") - self.fail("tag creation") - self.fail("tag deletion") - self.fail("remote deletion") + # tag ref + tag_name = "1.0.2" + light_tag = TagReference.create(rw_repo, tag_name) + self.failUnlessRaises(GitCommandError, TagReference.create, rw_repo, tag_name) + light_tag = TagReference.create(rw_repo, tag_name, "HEAD~1", force = True) + assert isinstance(light_tag, TagReference) + assert light_tag.name == tag_name + assert light_tag.commit == cur_head.commit.parents[0] + assert light_tag.tag is None + + # tag with tag object + other_tag_name = "releases/1.0.2RC" + msg = "my mighty tag\nsecond line" + obj_tag = TagReference.create(rw_repo, other_tag_name, message=msg) + assert isinstance(obj_tag, TagReference) + assert obj_tag.name == other_tag_name + assert obj_tag.commit == cur_head.commit + assert obj_tag.tag is not None + + TagReference.delete(rw_repo, light_tag, obj_tag) + tags = rw_repo.tags + assert light_tag not in tags and obj_tag not in tags + + # remote deletion + remote_refs_so_far = 0 + remotes = rw_repo.remotes + assert remotes + for remote in remotes: + refs = remote.refs + RemoteReference.delete(rw_repo, *refs) + remote_refs_so_far += len(refs) + # END for each ref to delete + assert remote_refs_so_far + + for remote in remotes: + # remotes without references throw + self.failUnlessRaises(AssertionError, getattr, remote, 'refs') + # END for each remote + + self.fail("set commit using ref.commit = that") |