Merge lp:~jelmer/brz/parse-git-error into lp:brz

Proposed by Jelmer Vernooij
Status: Merged
Approved by: Jelmer Vernooij
Approved revision: no longer in the source branch.
Merge reported by: The Breezy Bot
Merged at revision: not available
Proposed branch: lp:~jelmer/brz/parse-git-error
Merge into: lp:brz
Diff against target: 96 lines (+35/-5)
2 files modified
breezy/git/remote.py (+17/-4)
breezy/git/tests/test_remote.py (+18/-1)
To merge this branch: bzr merge lp:~jelmer/brz/parse-git-error
Reviewer Review Type Date Requested Status
Martin Packman Approve
Review via email: mp+354724@code.launchpad.net

Commit message

Improve error parsing for git repositories a bit.

Description of the change

Improve error parsing for git repositories a bit.

To post a comment you must log in.
Revision history for this message
Martin Packman (gz) wrote :

Looks reasonable, thanks!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'breezy/git/remote.py'
--- breezy/git/remote.py 2018-08-04 17:32:58 +0000
+++ breezy/git/remote.py 2018-09-11 19:38:53 +0000
@@ -45,6 +45,7 @@
45 NotBranchError,45 NotBranchError,
46 NotLocalUrl,46 NotLocalUrl,
47 NoWorkingTree,47 NoWorkingTree,
48 PermissionDenied,
48 UninitializableFormat,49 UninitializableFormat,
49 )50 )
50from ..revisiontree import RevisionTree51from ..revisiontree import RevisionTree
@@ -175,6 +176,16 @@
175 _fmt = "Remote server error: %(msg)s"176 _fmt = "Remote server error: %(msg)s"
176177
177178
179class HeadUpdateFailed(BzrError):
180
181 _fmt = ("Unable to update remote HEAD branch. To update the master "
182 "branch, specify the URL %(base_url)s,branch=master.")
183
184 def __init__(self, base_url):
185 super(HeadUpdateFailed, self).__init__()
186 self.base_url = base_url
187
188
178def parse_git_error(url, message):189def parse_git_error(url, message):
179 """Parse a remote git server error and return a bzr exception.190 """Parse a remote git server error and return a bzr exception.
180191
@@ -182,13 +193,15 @@
182 :param message: Message sent by the remote git server193 :param message: Message sent by the remote git server
183 """194 """
184 message = str(message).strip()195 message = str(message).strip()
185 if message.startswith("Could not find Repository "):196 if (message.startswith("Could not find Repository ") or
197 message == 'Repository not found.'):
186 return NotBranchError(url, message)198 return NotBranchError(url, message)
187 if message == "HEAD failed to update":199 if message == "HEAD failed to update":
188 base_url, _ = urlutils.split_segment_parameters(url)200 base_url, _ = urlutils.split_segment_parameters(url)
189 raise BzrError(201 return HeadUpdateFailed(base_url)
190 ("Unable to update remote HEAD branch. To update the master "202 if message.startswith('access denied or repository not exported:'):
191 "branch, specify the URL %s,branch=master.") % base_url)203 extra, path = message.split(': ', 1)
204 return PermissionDenied(path, extra)
192 # Don't know, just return it to the user as-is205 # Don't know, just return it to the user as-is
193 return RemoteGitError(message)206 return RemoteGitError(message)
194207
195208
=== modified file 'breezy/git/tests/test_remote.py'
--- breezy/git/tests/test_remote.py 2018-08-04 17:32:58 +0000
+++ breezy/git/tests/test_remote.py 2018-09-11 19:38:53 +0000
@@ -29,6 +29,7 @@
29 DivergedBranches,29 DivergedBranches,
30 NotBranchError,30 NotBranchError,
31 NoSuchTag,31 NoSuchTag,
32 PermissionDenied,
32 )33 )
3334
34from ...tests import (35from ...tests import (
@@ -41,6 +42,8 @@
41from ..remote import (42from ..remote import (
42 split_git_url,43 split_git_url,
43 parse_git_error,44 parse_git_error,
45 HeadUpdateFailed,
46 RemoteGitError,
44 RemoteGitBranchFormat,47 RemoteGitBranchFormat,
45 )48 )
4649
@@ -79,12 +82,26 @@
7982
80 def test_unknown(self):83 def test_unknown(self):
81 e = parse_git_error("url", "foo")84 e = parse_git_error("url", "foo")
82 self.assertIsInstance(e, BzrError)85 self.assertIsInstance(e, RemoteGitError)
8386
84 def test_notbrancherror(self):87 def test_notbrancherror(self):
85 e = parse_git_error("url", "\n Could not find Repository foo/bar")88 e = parse_git_error("url", "\n Could not find Repository foo/bar")
86 self.assertIsInstance(e, NotBranchError)89 self.assertIsInstance(e, NotBranchError)
8790
91 def test_notbrancherror_github(self):
92 e = parse_git_error("url", "Repository not found.\n")
93 self.assertIsInstance(e, NotBranchError)
94
95 def test_head_update(self):
96 e = parse_git_error("url", "HEAD failed to update\n")
97 self.assertIsInstance(e, HeadUpdateFailed)
98
99 def test_permission_dnied(self):
100 e = parse_git_error(
101 "url",
102 "access denied or repository not exported: /debian/altermime.git")
103 self.assertIsInstance(e, PermissionDenied)
104
88105
89class TestRemoteGitBranchFormat(TestCase):106class TestRemoteGitBranchFormat(TestCase):
90107

Subscribers

People subscribed via source and target branches