From f7b7eb6245e7d7c4535975268a9be936e2c59dc8 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Thu, 8 Jan 2015 09:45:50 +0100 Subject: Added Remote.exists() method, and test. Fixes #229 --- git/remote.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'git/remote.py') diff --git a/git/remote.py b/git/remote.py index 4d249004..deddd1f4 100644 --- a/git/remote.py +++ b/git/remote.py @@ -397,6 +397,19 @@ class Remote(LazyMixin, Iterable): def __hash__(self): return hash(self.name) + def exists(self): + """:return: True if this is a valid, existing remote. + Valid remotes have an entry in the repository's configuration""" + try: + self.config_reader.get('url') + return True + except cp.NoOptionError: + # we have the section at least ... + return True + except cp.NoSectionError: + return False + # end + @classmethod def iter_items(cls, repo): """:return: Iterator yielding Remote objects of the given repository""" -- cgit v1.2.3