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
1=== modified file 'breezy/git/remote.py'
2--- breezy/git/remote.py 2018-09-14 09:56:35 +0000
3+++ breezy/git/remote.py 2018-10-13 13:17:02 +0000
4@@ -203,6 +203,13 @@
5 if message.startswith('access denied or repository not exported:'):
6 extra, path = message.split(': ', 1)
7 return PermissionDenied(path, extra)
8+ if message.endswith('You are not allowed to push code to this project.'):
9+ return PermissionDenied(url, message)
10+ if message.endswith(' does not appear to be a git repository'):
11+ return NotBranchError(url, message)
12+ m = re.match(r'Permission to ([^ ]+) denied to ([^ ]+)\.', message)
13+ if m:
14+ return PermissionDenied(m.group(1), 'denied to %s' % m.group(2))
15 # Don't know, just return it to the user as-is
16 return RemoteGitError(message)
17
18@@ -350,7 +357,7 @@
19 def progress(self, text):
20 text = text.rstrip(b"\r\n")
21 text = text.decode('utf-8')
22- if text.startswith('error: '):
23+ if text.lower().startswith('error: '):
24 trace.show_error('git: %s', text[len(b'error: '):])
25 else:
26 trace.mutter("git: %s", text)
27
28=== modified file 'breezy/git/tests/test_remote.py'
29--- breezy/git/tests/test_remote.py 2018-09-12 16:42:02 +0000
30+++ breezy/git/tests/test_remote.py 2018-10-13 13:17:02 +0000
31@@ -96,6 +96,10 @@
32 e = parse_git_error("url", "Repository not found.\n")
33 self.assertIsInstance(e, NotBranchError)
34
35+ def test_notbrancherror_normal(self):
36+ e = parse_git_error("url", "fatal: '/srv/git/lintian-brush' does not appear to be a git repository")
37+ self.assertIsInstance(e, NotBranchError)
38+
39 def test_head_update(self):
40 e = parse_git_error("url", "HEAD failed to update\n")
41 self.assertIsInstance(e, HeadUpdateFailed)
42@@ -106,6 +110,20 @@
43 "access denied or repository not exported: /debian/altermime.git")
44 self.assertIsInstance(e, PermissionDenied)
45
46+ def test_permission_denied_gitlab(self):
47+ e = parse_git_error(
48+ "url",
49+ 'GitLab: You are not allowed to push code to this project.\n')
50+ self.assertIsInstance(e, PermissionDenied)
51+
52+ def test_permission_denied_github(self):
53+ e = parse_git_error(
54+ "url",
55+ 'Permission to porridge/gaduhistory.git denied to jelmer.')
56+ self.assertIsInstance(e, PermissionDenied)
57+ self.assertEqual(e.path, 'porridge/gaduhistory.git')
58+ self.assertEqual(e.extra, ': denied to jelmer')
59+
60
61 class TestRemoteGitBranchFormat(TestCase):
62

Subscribers

People subscribed via source and target branches