Skip to content
This repository
Browse code

better error message in case there's an error reading from the reposi…

…tory
  • Loading branch information...
commit 97a97a0e030e26948e4ea16f91533751f5929416 1 parent 39734dc
ejucovy authored August 20, 2012
8  trac_gitolite/perm_manager.py
@@ -25,8 +25,8 @@ class GitolitePermissionManager(Component):
25 25
                                         default="trac")
26 26
 
27 27
     def get_users(self):
28  
-        repo = self.env.get_repository(reponame=self.gitolite_admin_reponame)
29  
-        node = repo.get_node("keydir")
  28
+        node = utils.get_repo_node(self.env, self.gitolite_admin_reponame, 
  29
+                                   "keydir")
30 30
         assert node.isdir, "Node %s at /keydir/ is not a directory" % node
31 31
         for child in node.get_entries():
32 32
             name = child.get_name()
@@ -35,8 +35,8 @@ def get_users(self):
35 35
             yield name
36 36
 
37 37
     def read_config(self):
38  
-        repo = self.env.get_repository(reponame=self.gitolite_admin_reponame)
39  
-        node = repo.get_node("conf/gitolite.conf")
  38
+        node = utils.get_repo_node(self.env, self.gitolite_admin_reponame,
  39
+                                   "conf/gitolite.conf")
40 40
         fp = node.get_content()
41 41
         return utils.read_config(fp)
42 42
     
4  trac_gitolite/perm_policy.py
@@ -31,8 +31,8 @@ def parent_repository(self, resource):
31 31
             resource = resource.parent
32 32
 
33 33
     def read_config(self):
34  
-        repo = self.env.get_repository(reponame=self.gitolite_admin_reponame)
35  
-        node = repo.get_node("conf/gitolite.conf")
  34
+        node = utils.get_repo_node(self.env, self.gitolite_admin_reponame,
  35
+                                   "conf/gitolite.conf")
36 36
         fp = node.get_content()
37 37
         return utils.read_config(fp)
38 38
 
4  trac_gitolite/repo_manager.py
@@ -20,8 +20,8 @@ class GitoliteRepositoryManager(Component):
20 20
                                      default="git@localhost:gitolite-admin.git")
21 21
 
22 22
     def read_config(self):
23  
-        repo = self.env.get_repository(reponame=self.gitolite_admin_reponame)
24  
-        node = repo.get_node("conf/gitolite.conf")
  23
+        node = utils.get_repo_node(self.env, self.gitolite_admin_reponame,
  24
+                                   "conf/gitolite.conf")
25 25
         fp = node.get_content()
26 26
         return utils.read_config(fp)
27 27
     
4  trac_gitolite/user_manager.py
@@ -18,8 +18,8 @@ class GitoliteUserManager(Component):
18 18
                                      default="git@localhost:gitolite-admin.git")
19 19
 
20 20
     def get_users(self):
21  
-        repo = self.env.get_repository(reponame=self.gitolite_admin_reponame)
22  
-        node = repo.get_node("keydir")
  21
+        node = utils.get_repo_node(self.env, self.gitolite_admin_reponame, 
  22
+                                   "keydir")
23 23
         assert node.isdir, "Node %s at /keydir/ is not a directory" % node
24 24
         for child in node.get_entries():
25 25
             name = child.get_name()
13  trac_gitolite/utils.py
@@ -3,6 +3,19 @@
3 3
 from StringIO import StringIO
4 4
 from tempfile import mkdtemp
5 5
 
  6
+def get_repo_node(env, repo_name, node):
  7
+    try:
  8
+        from tracopt.versioncontrol.git.PyGIT import GitError
  9
+    except ImportError: ## Pre-1.0 Trac
  10
+        from tracext.git.PyGIT import GitError
  11
+    from trac.core import TracError
  12
+    try:
  13
+        repo = env.get_repository(reponame=repo_name)
  14
+        return repo.get_node(node)
  15
+    except GitError:
  16
+        raise TracError("Error reading Git files at %s; check your repository path (for repo %s) and file permissions" % (node, repo_name))
  17
+
  18
+
6 19
 def read_config(fp):
7 20
     repos = dict()
8 21
     this_repo = None

0 notes on commit 97a97a0

Please sign in to comment.
Something went wrong with that request. Please try again.