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>
Fri, 14 Nov 2014 12:47:19 +0000 (14:47 +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 54c755f6e220696fb6152abf9e34a461faa7b93c..6b21c252517d7711c90db980e00328f27a9724b2 100644 (file)
@@ -1187,10 +1187,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 b1a143265a5d346ee9884dc467b590bc912a6d98..e44b60b713e9763c4649aea5bd89df1e519b6ad4 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)