aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTommi Virtanen <tv@eagain.net>2007-09-03 21:16:15 -0700
committerTommi Virtanen <tv@eagain.net>2007-09-03 21:16:15 -0700
commit1f3924e2cb86081a5d8a6292c895f15a2664d0da (patch)
tree4a658f8db30b4423ca7dc6318870dd021968ac31
parentMake gitosis-init ignore error from non-existent config file. (diff)
downloadgitosis-dakkar-1f3924e2cb86081a5d8a6292c895f15a2664d0da.tar.gz
gitosis-dakkar-1f3924e2cb86081a5d8a6292c895f15a2664d0da.tar.bz2
gitosis-dakkar-1f3924e2cb86081a5d8a6292c895f15a2664d0da.zip
Make gitosis-init call run_hook.post_update directly.
This avoids complexity where failing to read the config file in gitosis-run-hook is non-fatal, but only on the first run. gitosis-init will take care of config file reading and just pass a RawConfigParser instance to run_hook.post_update.
-rw-r--r--gitosis/init.py26
-rw-r--r--gitosis/run_hook.py23
2 files changed, 16 insertions, 33 deletions
diff --git a/gitosis/init.py b/gitosis/init.py
index 0da6ed3..61504c8 100644
--- a/gitosis/init.py
+++ b/gitosis/init.py
@@ -6,7 +6,6 @@ import errno
import logging
import os
import re
-import subprocess
import sys
from pkg_resources import resource_filename
@@ -14,6 +13,7 @@ from cStringIO import StringIO
from ConfigParser import RawConfigParser
from gitosis import repository
+from gitosis import run_hook
from gitosis import util
from gitosis import app
@@ -51,23 +51,6 @@ def initial_commit(git_dir, cfg, pubkey, user):
],
)
-class PostUpdateFailedError(Exception):
- """post-update hook failed"""
-
- def __str__(self):
- return '%s: %s' % (self.__doc__, ': '.join(self.args))
-
-def run_post_update(git_dir):
- args = [os.path.join(git_dir, 'hooks', 'post-update')]
- returncode = subprocess.call(
- args=args,
- cwd=git_dir,
- close_fds=True,
- env=dict(GIT_DIR='.'),
- )
- if returncode != 0:
- raise PostUpdateFailedError('exit status %d' % returncode)
-
def symlink_config(git_dir):
dst = os.path.expanduser('~/.gitosis.conf')
tmp = '%s.%d.tmp' % (dst, os.getpid())
@@ -133,7 +116,6 @@ class Main(app.App):
def handle_args(self, parser, cfg, options, args):
super(Main, self).handle_args(parser, cfg, options, args)
- logging.basicConfig(level=logging.INFO)
os.umask(0022)
log.info('Reading SSH public key...')
@@ -153,11 +135,7 @@ class Main(app.App):
user=user,
)
log.info('Running post-update hook...')
- try:
- run_post_update(git_dir=admin_repository)
- except PostUpdateFailedError, e:
- log.error('%s', e)
- sys.exit(1)
+ run_hook.post_update(cfg=cfg, git_dir=admin_repository)
log.info('Symlinking ~/.gitosis.conf to repository...')
symlink_config(git_dir=admin_repository)
log.info('Done.')
diff --git a/gitosis/run_hook.py b/gitosis/run_hook.py
index de5076e..d249db1 100644
--- a/gitosis/run_hook.py
+++ b/gitosis/run_hook.py
@@ -13,20 +13,27 @@ from gitosis import ssh
from gitosis import gitweb
from gitosis import app
-def post_update(cfg):
+def post_update(cfg, git_dir):
+ export = os.path.join(git_dir, 'gitosis-export')
try:
- shutil.rmtree('gitosis-export')
+ shutil.rmtree(export)
except OSError, e:
if e.errno == errno.ENOENT:
pass
else:
raise
- repository.export(git_dir='.', path='gitosis-export')
- os.rename('gitosis-export/gitosis.conf', 'gitosis.conf')
- gitweb.generate(config=cfg, path='projects.list')
+ repository.export(git_dir=git_dir, path=export)
+ os.rename(
+ os.path.join(export, 'gitosis.conf'),
+ os.path.join(export, '..', 'gitosis.conf'),
+ )
+ gitweb.generate(
+ config=cfg,
+ path=os.path.join(git_dir, 'projects.list'),
+ )
ssh.writeAuthorizedKeys(
path=os.path.expanduser('~/.ssh/authorized_keys'),
- keydir='gitosis-export/keydir',
+ keydir=os.path.join(export, 'keydir'),
)
class Main(app.App):
@@ -50,12 +57,10 @@ class Main(app.App):
if git_dir is None:
log.error('Must have GIT_DIR set in enviroment')
sys.exit(1)
- os.chdir(git_dir)
- os.environ['GIT_DIR'] = '.'
if hook == 'post-update':
log.info('Running hook %s', hook)
- post_update(cfg)
+ post_update(cfg, git_dir)
log.info('Done.')
else:
log.warning('Ignoring unknown hook: %r', hook)