diff options
author | Sebastian Thiel <byronimo@gmail.com> | 2009-10-18 18:01:52 +0200 |
---|---|---|
committer | Sebastian Thiel <byronimo@gmail.com> | 2009-10-19 15:04:25 +0200 |
commit | a8f8582274cd6a368a79e569e2995cee7d6ea9f9 (patch) | |
tree | ff60fb48a7de1b0b4657c95a93aa70ff388eaa8b | |
parent | 8f42db54c6b2cfbd7d68e6d34ac2ed70578402f7 (diff) | |
download | gitpython-a8f8582274cd6a368a79e569e2995cee7d6ea9f9.tar.gz |
added initial frame for remote handling- remotes are somewhat related to either parsing the command output or to reading the repo configuration which would be faster
-rw-r--r-- | lib/git/refs.py | 46 | ||||
-rw-r--r-- | test/git/test_repo.py | 5 |
2 files changed, 23 insertions, 28 deletions
diff --git a/lib/git/refs.py b/lib/git/refs.py index 4445f252..1a58bb05 100644 --- a/lib/git/refs.py +++ b/lib/git/refs.py @@ -15,6 +15,7 @@ class Reference(LazyMixin, Iterable): Represents a named reference to any object """ __slots__ = ("repo", "path") + _common_path_default = "refs" def __init__(self, repo, path, object = None): """ @@ -75,7 +76,7 @@ class Reference(LazyMixin, Iterable): return Object.new(self.repo, self.path) @classmethod - def iter_items(cls, repo, common_path = "refs", **kwargs): + def iter_items(cls, repo, common_path = None, **kwargs): """ Find all refs in the repository @@ -84,7 +85,9 @@ class Reference(LazyMixin, Iterable): ``common_path`` Optional keyword argument to the path which is to be shared by all - returned Ref objects + returned Ref objects. + Defaults to class specific portion if None assuring that only + refs suitable for the actual class are returned. ``kwargs`` Additional options given as keyword arguments, will be passed @@ -100,7 +103,10 @@ class Reference(LazyMixin, Iterable): options = {'sort': "committerdate", 'format': "%(refname)%00%(objectname)%00%(objecttype)%00%(objectsize)"} - + + if common_path is None: + common_path = cls._common_path_default + options.update(kwargs) output = repo.git.for_each_ref(common_path, **options) @@ -157,7 +163,8 @@ class Head(Reference): >>> head.commit.id '1c09f116cbc2cb4100fb6935bb162daa4723f455' """ - + _common_path_default = "refs/heads" + @property def commit(self): """ @@ -166,20 +173,6 @@ class Head(Reference): """ return self.object - @classmethod - def iter_items(cls, repo, common_path = "refs/heads", **kwargs): - """ - Returns - Iterator yielding Head items - - For more documentation, please refer to git.base.Ref.list_items - """ - return super(Head,cls).iter_items(repo, common_path, **kwargs) - - def __repr__(self): - return '<git.Head "%s">' % self.name - - class TagRef(Reference): """ @@ -197,6 +190,7 @@ class TagRef(Reference): """ __slots__ = tuple() + _common_path_default = "refs/tags" @property def commit(self): @@ -223,16 +217,12 @@ class TagRef(Reference): return self.object return None - @classmethod - def iter_items(cls, repo, common_path = "refs/tags", **kwargs): - """ - Returns - Iterator yielding commit items - - For more documentation, please refer to git.base.Ref.list_items - """ - return super(TagRef,cls).iter_items(repo, common_path, **kwargs) - # provide an alias Tag = TagRef + +class RemoteRef(Head): + """ + Represents a reference pointing to a remote head. + """ + _common_path_default = "refs/remotes" diff --git a/test/git/test_repo.py b/test/git/test_repo.py index 0d8a473d..b30f6889 100644 --- a/test/git/test_repo.py +++ b/test/git/test_repo.py @@ -34,6 +34,11 @@ class TestRepo(TestCase): for head in self.repo.heads: assert_equal(Head, head.__class__) + def test_renites_should_return_array_of_remote_objects(self): + for remote in self.repo.remotes: + assert_equal(Remote, remote.__class__) + + def test_heads_should_populate_head_data(self): for head in self.repo.heads: assert head.name |