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

Proposed by Jelmer Vernooij on 2018-09-11
Status: Merged
Approved by: Jelmer Vernooij on 2018-09-12
Approved revision: 7106
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 2018-09-11 Approve on 2018-09-11
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.
lp:~jelmer/brz/parse-git-error updated on 2018-09-11
7105. By Jelmer Vernooij on 2018-09-11

Handle PermissionDenied.

7106. By Jelmer Vernooij on 2018-09-11

Strip space.

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
1=== modified file 'breezy/git/remote.py'
2--- breezy/git/remote.py 2018-08-04 17:32:58 +0000
3+++ breezy/git/remote.py 2018-09-11 19:38:53 +0000
4@@ -45,6 +45,7 @@
5 NotBranchError,
6 NotLocalUrl,
7 NoWorkingTree,
8+ PermissionDenied,
9 UninitializableFormat,
10 )
11 from ..revisiontree import RevisionTree
12@@ -175,6 +176,16 @@
13 _fmt = "Remote server error: %(msg)s"
14
15
16+class HeadUpdateFailed(BzrError):
17+
18+ _fmt = ("Unable to update remote HEAD branch. To update the master "
19+ "branch, specify the URL %(base_url)s,branch=master.")
20+
21+ def __init__(self, base_url):
22+ super(HeadUpdateFailed, self).__init__()
23+ self.base_url = base_url
24+
25+
26 def parse_git_error(url, message):
27 """Parse a remote git server error and return a bzr exception.
28
29@@ -182,13 +193,15 @@
30 :param message: Message sent by the remote git server
31 """
32 message = str(message).strip()
33- if message.startswith("Could not find Repository "):
34+ if (message.startswith("Could not find Repository ") or
35+ message == 'Repository not found.'):
36 return NotBranchError(url, message)
37 if message == "HEAD failed to update":
38 base_url, _ = urlutils.split_segment_parameters(url)
39- raise BzrError(
40- ("Unable to update remote HEAD branch. To update the master "
41- "branch, specify the URL %s,branch=master.") % base_url)
42+ return HeadUpdateFailed(base_url)
43+ if message.startswith('access denied or repository not exported:'):
44+ extra, path = message.split(': ', 1)
45+ return PermissionDenied(path, extra)
46 # Don't know, just return it to the user as-is
47 return RemoteGitError(message)
48
49
50=== modified file 'breezy/git/tests/test_remote.py'
51--- breezy/git/tests/test_remote.py 2018-08-04 17:32:58 +0000
52+++ breezy/git/tests/test_remote.py 2018-09-11 19:38:53 +0000
53@@ -29,6 +29,7 @@
54 DivergedBranches,
55 NotBranchError,
56 NoSuchTag,
57+ PermissionDenied,
58 )
59
60 from ...tests import (
61@@ -41,6 +42,8 @@
62 from ..remote import (
63 split_git_url,
64 parse_git_error,
65+ HeadUpdateFailed,
66+ RemoteGitError,
67 RemoteGitBranchFormat,
68 )
69
70@@ -79,12 +82,26 @@
71
72 def test_unknown(self):
73 e = parse_git_error("url", "foo")
74- self.assertIsInstance(e, BzrError)
75+ self.assertIsInstance(e, RemoteGitError)
76
77 def test_notbrancherror(self):
78 e = parse_git_error("url", "\n Could not find Repository foo/bar")
79 self.assertIsInstance(e, NotBranchError)
80
81+ def test_notbrancherror_github(self):
82+ e = parse_git_error("url", "Repository not found.\n")
83+ self.assertIsInstance(e, NotBranchError)
84+
85+ def test_head_update(self):
86+ e = parse_git_error("url", "HEAD failed to update\n")
87+ self.assertIsInstance(e, HeadUpdateFailed)
88+
89+ def test_permission_dnied(self):
90+ e = parse_git_error(
91+ "url",
92+ "access denied or repository not exported: /debian/altermime.git")
93+ self.assertIsInstance(e, PermissionDenied)
94+
95
96 class TestRemoteGitBranchFormat(TestCase):
97

Subscribers

People subscribed via source and target branches