diff options
author | Sebastian Thiel <byronimo@gmail.com> | 2009-10-19 21:32:34 +0200 |
---|---|---|
committer | Sebastian Thiel <byronimo@gmail.com> | 2009-10-19 21:32:34 +0200 |
commit | 985093bae160419782b3d3cb9151e2e58625fd52 (patch) | |
tree | 2f19b97289d9d0af2eeea894dcc1f51e627261cf /lib/git/refs.py | |
parent | 8f42db54c6b2cfbd7d68e6d34ac2ed70578402f7 (diff) | |
parent | 53d26977f1aff8289f13c02ee672349d78eeb2f0 (diff) | |
download | gitpython-985093bae160419782b3d3cb9151e2e58625fd52.tar.gz |
Merge branch 'remotes' into improvements
* remotes:
remote: added tests for creation and removal, finishing the remote interface
remote: base tests succeed now
config: fixed serious issues that would cause it to see initial tabs as continuation lines - this leads to very incorrect results when parsing git config files. Now the complete reading is overridden to make it work as there was no other way
Added configuration access including tests to remote
Added remote module and test cases - about to implement remote option handling
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
Diffstat (limited to 'lib/git/refs.py')
-rw-r--r-- | lib/git/refs.py | 67 |
1 files changed, 40 insertions, 27 deletions
diff --git a/lib/git/refs.py b/lib/git/refs.py index 4445f252..618babc2 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,35 @@ class TagRef(Reference): return self.object return None - @classmethod - def iter_items(cls, repo, common_path = "refs/tags", **kwargs): + +# provide an alias +Tag = TagRef + +class RemoteRef(Head): + """ + Represents a reference pointing to a remote head. + """ + _common_path_default = "refs/remotes" + + @property + def remote_name(self): """ Returns - Iterator yielding commit items - - For more documentation, please refer to git.base.Ref.list_items + Name of the remote we are a reference of, such as 'origin' for a reference + named 'origin/master' """ - return super(TagRef,cls).iter_items(repo, common_path, **kwargs) - + tokens = self.path.split('/') + # /refs/remotes/<remote name>/<branch_name> + return tokens[2] -# provide an alias -Tag = TagRef + @property + def remote_branch(self): + """ + Returns + Name of the remote branch itself, i.e. master. + + NOTE: The returned name is usually not qualified enough to uniquely identify + a branch + """ + tokens = self.path.split('/') + return '/'.join(tokens[3:]) |