GitRepository/get_remote_repos: return URLs, too
authorMarkus Lehtonen <markus.lehtonen@linux.intel.com>
Mon, 3 Dec 2012 08:21:43 +0000 (10:21 +0200)
committerMarkus Lehtonen <markus.lehtonen@linux.intel.com>
Tue, 7 Jan 2014 14:21:31 +0000 (16:21 +0200)
In addition to the remote name, return remote URLs. Return value is now
a dict with remote name as the key and a list of URLs as the value. The
first value in the list is the effective fetch URL, the rest of the
values are push URLs.

NOTE! This patch is to be dropped, not going for upstream.

Signed-off-by: Markus Lehtonen <markus.lehtonen@linux.intel.com>
gbp/git/repository.py
tests/test_GitRepository.py

index e20adfbfe26d4ed731d81bef77e7686249e85be7..be65713a74c4fa7a9043bbfaa568e9b8b0d824b3 100644 (file)
@@ -1177,10 +1177,25 @@ class GitRepository(object):
         @deprecated: Use get_remotes() instead
 
         @return: remote repositories
-        @rtype: C{list} of C{str}
+        @rtype: C{dict} of C{list} of C{str}
         """
-        out = self._git_getoutput('remote')[0]
-        return [ remote.strip() for remote in out ]
+        stdout, stderr, ret = self._git_inout('remote', ['-v'],
+                                              capture_stderr=True)
+        if ret:
+            raise GitRepositoryError('Failed to get remotes: %s' % stderr)
+
+        remotes = {}
+        for rem in stdout.splitlines():
+            name, url_urltype = rem.split('\t', 1)
+            url, urltype = url_urltype.rsplit(' ', 1)
+            urltype = urltype.strip('()')
+            if not name in remotes:
+                remotes[name] = ['']
+            if urltype == 'fetch':
+                remotes[name][0] = url
+            else:
+                remotes[name].append(url)
+        return remotes
 
     def has_remote_repo(self, name):
         """
index 0b005f5e9656628a2bb4504f46f8b02ec23593ad..480f0c3b4a386a00bde3b96385dd772bca2ee051 100644 (file)
@@ -577,8 +577,9 @@ def test_clone():
     >>> clone.get_merge_branch('bar') # None if no merge branch exists
     >>> clone.get_local_branches()
     ['bar', 'foo', 'master']
-    >>> clone.get_remote_repos()
-    ['origin']
+    >>> remotes = clone.get_remote_repos()
+    >>> {'origin': [repo_dir, repo_dir]} == remotes
+    True
     >>> clone.has_remote_repo('origin')
     True
     >>> clone.has_branch('origin/master', remote=True)