aboutsummaryrefslogtreecommitdiffhomepage
path: root/gbp
diff options
context:
space:
mode:
authorMarkus Lehtonen <markus.lehtonen@linux.intel.com>2013-09-05 09:53:57 +0300
committerGuido Günther <agx@sigxcpu.org>2013-09-10 09:19:26 +0200
commit3eb401db658a5143e06f2d29a292e9be5b8a623a (patch)
tree7af6db9130c9099809af29c518af82ba26b636a6 /gbp
parentdb79c5db34498bc353f7d1e10bb1f4b7140d876b (diff)
git: new class and method for remote repositories
Add a new GitRemote class for representing git remote repositories. The initial, very limited, version only contains information about the fetch and push URLs of the remote repository. Also, add a new GitRepository.get_remotes() method for getting remote repositories as instances of the new GitRemote class. Signed-off-by: Markus Lehtonen <markus.lehtonen@linux.intel.com>
Diffstat (limited to 'gbp')
-rw-r--r--gbp/git/repository.py61
1 files changed, 61 insertions, 0 deletions
diff --git a/gbp/git/repository.py b/gbp/git/repository.py
index fc7857b9..17c1aa47 100644
--- a/gbp/git/repository.py
+++ b/gbp/git/repository.py
@@ -34,6 +34,35 @@ class GitRepositoryError(GitError):
pass
+class GitRemote(object):
+ """Class representing a remote repository"""
+ def __init__(self, name, fetch_url, push_urls):
+ self._name = name
+ self._fetch_url = fetch_url
+ if isinstance(push_urls, basestring):
+ self._push_urls = [push_urls]
+ else:
+ self._push_urls = [url for url in push_urls]
+
+ def __str__(self):
+ return self.name
+
+ @property
+ def name(self):
+ """Name of the remote"""
+ return self._name
+
+ @property
+ def fetch_url(self):
+ """Fetch URL"""
+ return self._fetch_url
+
+ @property
+ def push_urls(self):
+ """List of push URLs"""
+ return self._push_urls
+
+
class GitRepository(object):
"""
Represents a git repository at I{path}. It's currently assumed that the git
@@ -989,6 +1018,38 @@ class GitRepository(object):
#{ Remote Repositories
+ def get_remotes(self):
+ """
+ Get a list of remote repositories
+
+ @return: remote repositories
+ @rtype: C{dict} of C{GitRemote}
+ """
+ out, err, ret = self._git_inout('remote', [], capture_stderr=True)
+ if ret:
+ raise GitRepositoryError('Failed to get list of remotes: %s' % err)
+
+ # Get information about all remotes
+ remotes = {}
+ for remote in out.splitlines():
+ out, err, _ret = self._git_inout('remote', ['show', '-n', remote],
+ capture_stderr=True)
+ if ret:
+ raise GitRepositoryError('Failed to get information for remote '
+ '%s: %s' % (remote, err))
+ fetch_url = None
+ push_urls = []
+ for line in out.splitlines():
+ match = re.match('\s*Fetch\s+URL:\s*(\S.*)', line)
+ if match:
+ fetch_url = match.group(1)
+ match = re.match('\s*Push\s+URL:\s*(\S.*)', line)
+ if match:
+ push_urls.append(match.group(1))
+ remotes[remote] = GitRemote(remote, fetch_url, push_urls)
+
+ return remotes
+
def get_remote_repos(self):
"""
Get all remote repositories