repository: update get_remote_repos() to return the urls.
authorwanchao-xu <wanchao.xu@samsung.com>
Fri, 26 Apr 2024 09:06:23 +0000 (17:06 +0800)
committerwanchao-xu <wanchao.xu@samsung.com>
Fri, 26 Apr 2024 09:06:23 +0000 (17:06 +0800)
Change-Id: I483a1f3fc29e733a968c56029562da7c12a1b71e
Signed-off-by: wanchao-xu <wanchao.xu@samsung.com>
gbp/git/repository.py
tests/doctests/test_GitRepository.py

index e7f98cfa4f0519b0a00e1cd0c4b38970af4db3a2..a851620f011844a0c53b68ba54090763a840117c 100644 (file)
@@ -1221,10 +1221,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.decode().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.decode().strip())
+
+        remotes = {}
+        for rem in stdout.splitlines():
+            name, url_urltype = rem.decode().strip().split('\t', 1)
+            url, urltype = url_urltype.rsplit(' ', 1)
+            urltype = urltype.strip('()')
+            if name not 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 5b3c8f4eb5e22a0fa636b9cc0c8eb2649a137ca4..7d96a9b1c701bd3941ecce3a54cf6319f435cfdd 100644 (file)
@@ -635,7 +635,6 @@ def test_clone():
          - L{gbp.git.GitRepository.get_merge_branch}
          - L{gbp.git.GitRepository.get_remote_branches}
          - L{gbp.git.GitRepository.get_local_branches}
-         - L{gbp.git.GitRepository.get_remote_repos}
          - L{gbp.git.GitRepository.has_remote_repo}
 
     >>> import gbp.git
@@ -659,8 +658,6 @@ 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']
     >>> clone.has_remote_repo('origin')
     True
     >>> clone.has_branch('origin/master', remote=True)