@@ -15,6 +15,7 @@ class Reference(LazyMixin, Iterable):
1515 Represents a named reference to any object
1616 """
1717 __slots__ = ("repo" , "path" )
18+ _common_path_default = "refs"
1819
1920 def __init__ (self , repo , path , object = None ):
2021 """
@@ -75,7 +76,7 @@ def object(self):
7576 return Object .new (self .repo , self .path )
7677
7778 @classmethod
78- def iter_items (cls , repo , common_path = "refs" , ** kwargs ):
79+ def iter_items (cls , repo , common_path = None , ** kwargs ):
7980 """
8081 Find all refs in the repository
8182
@@ -84,7 +85,9 @@ def iter_items(cls, repo, common_path = "refs", **kwargs):
8485
8586 ``common_path``
8687 Optional keyword argument to the path which is to be shared by all
87- returned Ref objects
88+ returned Ref objects.
89+ Defaults to class specific portion if None assuring that only
90+ refs suitable for the actual class are returned.
8891
8992 ``kwargs``
9093 Additional options given as keyword arguments, will be passed
@@ -100,7 +103,10 @@ def iter_items(cls, repo, common_path = "refs", **kwargs):
100103
101104 options = {'sort' : "committerdate" ,
102105 'format' : "%(refname)%00%(objectname)%00%(objecttype)%00%(objectsize)" }
103-
106+
107+ if common_path is None :
108+ common_path = cls ._common_path_default
109+
104110 options .update (kwargs )
105111
106112 output = repo .git .for_each_ref (common_path , ** options )
@@ -157,7 +163,8 @@ class Head(Reference):
157163 >>> head.commit.id
158164 '1c09f116cbc2cb4100fb6935bb162daa4723f455'
159165 """
160-
166+ _common_path_default = "refs/heads"
167+
161168 @property
162169 def commit (self ):
163170 """
@@ -166,20 +173,6 @@ def commit(self):
166173 """
167174 return self .object
168175
169- @classmethod
170- def iter_items (cls , repo , common_path = "refs/heads" , ** kwargs ):
171- """
172- Returns
173- Iterator yielding Head items
174-
175- For more documentation, please refer to git.base.Ref.list_items
176- """
177- return super (Head ,cls ).iter_items (repo , common_path , ** kwargs )
178-
179- def __repr__ (self ):
180- return '<git.Head "%s">' % self .name
181-
182-
183176
184177class TagRef (Reference ):
185178 """
@@ -197,6 +190,7 @@ class TagRef(Reference):
197190 """
198191
199192 __slots__ = tuple ()
193+ _common_path_default = "refs/tags"
200194
201195 @property
202196 def commit (self ):
@@ -223,16 +217,12 @@ def tag(self):
223217 return self .object
224218 return None
225219
226- @classmethod
227- def iter_items (cls , repo , common_path = "refs/tags" , ** kwargs ):
228- """
229- Returns
230- Iterator yielding commit items
231-
232- For more documentation, please refer to git.base.Ref.list_items
233- """
234- return super (TagRef ,cls ).iter_items (repo , common_path , ** kwargs )
235-
236220
237221# provide an alias
238222Tag = TagRef
223+
224+ class RemoteRef (Head ):
225+ """
226+ Represents a reference pointing to a remote head.
227+ """
228+ _common_path_default = "refs/remotes"
0 commit comments