Commits

ejucovy  committed dd76ce7

update repo permissions by cloning repo to a tempdir, saving and committing there, and pushing to the origin

  • Participants
  • Parent commits a6a85b6

Comments (0)

Files changed (2)

File trac_gitolite/conf_writer.py

 from trac.core import *
 from trac.config import Option, BoolOption
 from trac.util.translation import _
+from trac.versioncontrol import DbRepositoryProvider
 from trac.web.chrome import ITemplateProvider
 from trac.web.chrome import add_notice
 
                 if user not in perms[repo][perm]:
                     perms[repo][perm].append(user)
 
-            ## do the actual saving of the file here
+            db_provider = self.env[DbRepositoryProvider]
+            repo_dir = dict(db_provider.get_repositories())[self.gitolite_admin_reponame]['dir']
+            utils.save_file(repo_dir, 'conf/gitolite.conf', 
+                            utils.to_string(perms),
+                            _('Updating repository permissions'))
 
             add_notice(req, _('The permissions have been updated.'))
             req.redirect(req.href.admin(category, page))

File trac_gitolite/utils.py

+import os
+import subprocess
 from StringIO import StringIO
+from tempfile import mkdtemp
 
 def read_config(fp):
     repos = dict()
     fp.seek(0)
     return fp.read()
 
+def save_file(repo_path, file_path, contents, msg):
+    tempdir = mkdtemp()
+    subprocess.check_call(['git', 'clone', repo_path, tempdir])
+    fp = open(os.path.join(tempdir, file_path), 'w')
+    fp.write(contents)
+    fp.close()
+    subprocess.check_call(['git', 'add', file_path], cwd=tempdir)
+    subprocess.check_call(['git', 'commit', '-m', msg], cwd=tempdir)
+    subprocess.check_call(['git', 'push'], cwd=tempdir)