From dec4663129f72321a14efd6de63f14a7419e3ed2 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Tue, 23 Nov 2010 09:14:17 +0100 Subject: Split ref implementation up into multiple files, to make room for the log implementation --- refs/remote.py | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 refs/remote.py (limited to 'refs/remote.py') diff --git a/refs/remote.py b/refs/remote.py new file mode 100644 index 00000000..7ea9eb46 --- /dev/null +++ b/refs/remote.py @@ -0,0 +1,57 @@ +from head import Head +from git.util import join_path + +import os + + +__all__ = ["RemoteReference"] + + +class RemoteReference(Head): + """Represents a reference pointing to a remote head.""" + _common_path_default = "refs/remotes" + + + @classmethod + def iter_items(cls, repo, common_path = None, remote=None): + """Iterate remote references, and if given, constrain them to the given remote""" + common_path = common_path or cls._common_path_default + if remote is not None: + common_path = join_path(common_path, str(remote)) + # END handle remote constraint + return super(RemoteReference, cls).iter_items(repo, common_path) + + @property + 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// + return tokens[2] + + @property + 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:]) + + @classmethod + def delete(cls, repo, *refs, **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", *refs) + # the official deletion method will ignore remote symbolic refs - these + # are generally ignored in the refs/ folder. We don't though + # and delete remainders manually + for ref in refs: + try: + os.remove(join(repo.git_dir, ref.path)) + except OSError: + pass + # END for each ref -- cgit v1.2.3 From 739fa140235cc9d65c632eaf1f5cacc944d87cfb Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Tue, 23 Nov 2010 09:34:44 +0100 Subject: Fixed remaining tests - lets hope that everything is indeed working correctly - as imports changed, every line of code needs to be run to assure all names can be resolved --- refs/remote.py | 1 + 1 file changed, 1 insertion(+) (limited to 'refs/remote.py') diff --git a/refs/remote.py b/refs/remote.py index 7ea9eb46..85dc0f1e 100644 --- a/refs/remote.py +++ b/refs/remote.py @@ -1,5 +1,6 @@ from head import Head from git.util import join_path +from gitdb.util import join import os -- cgit v1.2.3 From a17c43d0662bab137903075f2cff34bcabc7e1d1 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Wed, 24 Nov 2010 12:30:51 +0100 Subject: Made previously protected methods public to introduce a method with reflog support which cannot be exposed using the respective property. Ref-Creation is now fully implemented in python. For details, see doc/source/changes.rst --- refs/remote.py | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'refs/remote.py') diff --git a/refs/remote.py b/refs/remote.py index 85dc0f1e..b7b07d4b 100644 --- a/refs/remote.py +++ b/refs/remote.py @@ -56,3 +56,8 @@ class RemoteReference(Head): except OSError: pass # END for each ref + + @classmethod + def create(cls, *args, **kwargs): + """Used to disable this method""" + raise TypeError("Cannot explicitly create remote references") -- cgit v1.2.3