Merge lp:~jelmer/brz/more-git-errors 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/more-git-errors
Merge into: lp:brz
Diff against target: 61 lines (+26/-1)
2 files modified
breezy/git/remote.py (+8/-1)
breezy/git/tests/test_remote.py (+18/-0)
To merge this branch: bzr merge lp:~jelmer/brz/more-git-errors
Reviewer Review Type Date Requested Status
Martin Packman Approve
Review via email: mp+355811@code.launchpad.net

Commit message

Handle some more Git error strings and convert them to specific exceptions.

Description of the change

Handle permission denied by GitLab.

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

Looks good, but seem one suggestion inline.

review: Approve
Revision history for this message
Jelmer Vernooij (jelmer) :

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-09-14 09:56:35 +0000
+++ breezy/git/remote.py 2018-10-13 13:17:02 +0000
@@ -203,6 +203,13 @@
203 if message.startswith('access denied or repository not exported:'):203 if message.startswith('access denied or repository not exported:'):
204 extra, path = message.split(': ', 1)204 extra, path = message.split(': ', 1)
205 return PermissionDenied(path, extra)205 return PermissionDenied(path, extra)
206 if message.endswith('You are not allowed to push code to this project.'):
207 return PermissionDenied(url, message)
208 if message.endswith(' does not appear to be a git repository'):
209 return NotBranchError(url, message)
210 m = re.match(r'Permission to ([^ ]+) denied to ([^ ]+)\.', message)
211 if m:
212 return PermissionDenied(m.group(1), 'denied to %s' % m.group(2))
206 # Don't know, just return it to the user as-is213 # Don't know, just return it to the user as-is
207 return RemoteGitError(message)214 return RemoteGitError(message)
208215
@@ -350,7 +357,7 @@
350 def progress(self, text):357 def progress(self, text):
351 text = text.rstrip(b"\r\n")358 text = text.rstrip(b"\r\n")
352 text = text.decode('utf-8')359 text = text.decode('utf-8')
353 if text.startswith('error: '):360 if text.lower().startswith('error: '):
354 trace.show_error('git: %s', text[len(b'error: '):])361 trace.show_error('git: %s', text[len(b'error: '):])
355 else:362 else:
356 trace.mutter("git: %s", text)363 trace.mutter("git: %s", text)
357364
=== modified file 'breezy/git/tests/test_remote.py'
--- breezy/git/tests/test_remote.py 2018-09-12 16:42:02 +0000
+++ breezy/git/tests/test_remote.py 2018-10-13 13:17:02 +0000
@@ -96,6 +96,10 @@
96 e = parse_git_error("url", "Repository not found.\n")96 e = parse_git_error("url", "Repository not found.\n")
97 self.assertIsInstance(e, NotBranchError)97 self.assertIsInstance(e, NotBranchError)
9898
99 def test_notbrancherror_normal(self):
100 e = parse_git_error("url", "fatal: '/srv/git/lintian-brush' does not appear to be a git repository")
101 self.assertIsInstance(e, NotBranchError)
102
99 def test_head_update(self):103 def test_head_update(self):
100 e = parse_git_error("url", "HEAD failed to update\n")104 e = parse_git_error("url", "HEAD failed to update\n")
101 self.assertIsInstance(e, HeadUpdateFailed)105 self.assertIsInstance(e, HeadUpdateFailed)
@@ -106,6 +110,20 @@
106 "access denied or repository not exported: /debian/altermime.git")110 "access denied or repository not exported: /debian/altermime.git")
107 self.assertIsInstance(e, PermissionDenied)111 self.assertIsInstance(e, PermissionDenied)
108112
113 def test_permission_denied_gitlab(self):
114 e = parse_git_error(
115 "url",
116 'GitLab: You are not allowed to push code to this project.\n')
117 self.assertIsInstance(e, PermissionDenied)
118
119 def test_permission_denied_github(self):
120 e = parse_git_error(
121 "url",
122 'Permission to porridge/gaduhistory.git denied to jelmer.')
123 self.assertIsInstance(e, PermissionDenied)
124 self.assertEqual(e.path, 'porridge/gaduhistory.git')
125 self.assertEqual(e.extra, ': denied to jelmer')
126
109127
110class TestRemoteGitBranchFormat(TestCase):128class TestRemoteGitBranchFormat(TestCase):
111129

Subscribers

People subscribed via source and target branches