summaryrefslogtreecommitdiff
path: root/git/refs/reference.py
diff options
context:
space:
mode:
authorSebastian Thiel <byronimo@gmail.com>2011-07-04 23:12:25 +0200
committerSebastian Thiel <byronimo@gmail.com>2011-07-04 23:42:54 +0200
commit87c7a6f1b166694b1d789b9d6ff8fb02585f099f (patch)
treeae2a933f0cacf4c095889226633f0eabf1c91de0 /git/refs/reference.py
parent87aa78c4d6c47874a68c8e1eb2bb8ae9d35e6253 (diff)
downloadgitpython-87c7a6f1b166694b1d789b9d6ff8fb02585f099f.tar.gz
Basic remote functionality moved to Reference type, as it can in fact be useful for tags as well, which might end up somewhere in the refs/remotes space. Its not likely that it will ever be used on a pure Reference instance though, but it is the smallest common base
Diffstat (limited to 'git/refs/reference.py')
-rw-r--r--git/refs/reference.py41
1 files changed, 41 insertions, 0 deletions
diff --git a/git/refs/reference.py b/git/refs/reference.py
index bd9c47a6..d85b194d 100644
--- a/git/refs/reference.py
+++ b/git/refs/reference.py
@@ -11,6 +11,18 @@ from git.util import (
__all__ = ["Reference"]
+#{ Utilities
+def require_remote_ref_path(func):
+ """A decorator raising a TypeError if we are not a valid remote, based on the path"""
+ def wrapper(self, *args):
+ if not self.path.startswith(self._remote_common_path_default + "/"):
+ raise ValueError("ref path does not point to a remote reference: %s" % path)
+ return func(self, *args)
+ #END wrapper
+ wrapper.__name__ = func.__name__
+ return wrapper
+#}END utilites
+
class Reference(SymbolicReference, LazyMixin, Iterable):
"""Represents a named reference to any object. Subclasses may apply restrictions though,
@@ -36,6 +48,8 @@ class Reference(SymbolicReference, LazyMixin, Iterable):
def __str__(self):
return self.name
+
+ #{ Interface
def set_object(self, object, logmsg = None):
"""Special version which checks if the head-log needs an update as well"""
@@ -82,3 +96,30 @@ class Reference(SymbolicReference, LazyMixin, Iterable):
"""Equivalent to SymbolicReference.iter_items, but will return non-detached
references as well."""
return cls._iter_items(repo, common_path)
+
+ #}END interface
+
+
+ #{ Remote Interface
+
+ @property
+ @require_remote_ref_path
+ def remote_name(self):
+ """
+ :return:
+ Name of the remote we are a reference of, such as 'origin' for a reference
+ named 'origin/master'"""
+ tokens = self.path.split('/')
+ # /refs/remotes/<remote name>/<branch_name>
+ return tokens[2]
+
+ @property
+ @require_remote_ref_path
+ def remote_head(self):
+ """:return: Name of the remote head 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:])
+
+ #} END remote interface