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.
This commit is contained in:
parent
1dfe84754a
commit
1f3924e2cb
|
@ -6,7 +6,6 @@ import errno
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import subprocess
|
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from pkg_resources import resource_filename
|
from pkg_resources import resource_filename
|
||||||
|
@ -14,6 +13,7 @@ from cStringIO import StringIO
|
||||||
from ConfigParser import RawConfigParser
|
from ConfigParser import RawConfigParser
|
||||||
|
|
||||||
from gitosis import repository
|
from gitosis import repository
|
||||||
|
from gitosis import run_hook
|
||||||
from gitosis import util
|
from gitosis import util
|
||||||
from gitosis import app
|
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):
|
def symlink_config(git_dir):
|
||||||
dst = os.path.expanduser('~/.gitosis.conf')
|
dst = os.path.expanduser('~/.gitosis.conf')
|
||||||
tmp = '%s.%d.tmp' % (dst, os.getpid())
|
tmp = '%s.%d.tmp' % (dst, os.getpid())
|
||||||
|
@ -133,7 +116,6 @@ class Main(app.App):
|
||||||
def handle_args(self, parser, cfg, options, args):
|
def handle_args(self, parser, cfg, options, args):
|
||||||
super(Main, self).handle_args(parser, cfg, options, args)
|
super(Main, self).handle_args(parser, cfg, options, args)
|
||||||
|
|
||||||
logging.basicConfig(level=logging.INFO)
|
|
||||||
os.umask(0022)
|
os.umask(0022)
|
||||||
|
|
||||||
log.info('Reading SSH public key...')
|
log.info('Reading SSH public key...')
|
||||||
|
@ -153,11 +135,7 @@ class Main(app.App):
|
||||||
user=user,
|
user=user,
|
||||||
)
|
)
|
||||||
log.info('Running post-update hook...')
|
log.info('Running post-update hook...')
|
||||||
try:
|
run_hook.post_update(cfg=cfg, git_dir=admin_repository)
|
||||||
run_post_update(git_dir=admin_repository)
|
|
||||||
except PostUpdateFailedError, e:
|
|
||||||
log.error('%s', e)
|
|
||||||
sys.exit(1)
|
|
||||||
log.info('Symlinking ~/.gitosis.conf to repository...')
|
log.info('Symlinking ~/.gitosis.conf to repository...')
|
||||||
symlink_config(git_dir=admin_repository)
|
symlink_config(git_dir=admin_repository)
|
||||||
log.info('Done.')
|
log.info('Done.')
|
||||||
|
|
|
@ -13,20 +13,27 @@ from gitosis import ssh
|
||||||
from gitosis import gitweb
|
from gitosis import gitweb
|
||||||
from gitosis import app
|
from gitosis import app
|
||||||
|
|
||||||
def post_update(cfg):
|
def post_update(cfg, git_dir):
|
||||||
|
export = os.path.join(git_dir, 'gitosis-export')
|
||||||
try:
|
try:
|
||||||
shutil.rmtree('gitosis-export')
|
shutil.rmtree(export)
|
||||||
except OSError, e:
|
except OSError, e:
|
||||||
if e.errno == errno.ENOENT:
|
if e.errno == errno.ENOENT:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
raise
|
raise
|
||||||
repository.export(git_dir='.', path='gitosis-export')
|
repository.export(git_dir=git_dir, path=export)
|
||||||
os.rename('gitosis-export/gitosis.conf', 'gitosis.conf')
|
os.rename(
|
||||||
gitweb.generate(config=cfg, path='projects.list')
|
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(
|
ssh.writeAuthorizedKeys(
|
||||||
path=os.path.expanduser('~/.ssh/authorized_keys'),
|
path=os.path.expanduser('~/.ssh/authorized_keys'),
|
||||||
keydir='gitosis-export/keydir',
|
keydir=os.path.join(export, 'keydir'),
|
||||||
)
|
)
|
||||||
|
|
||||||
class Main(app.App):
|
class Main(app.App):
|
||||||
|
@ -50,12 +57,10 @@ class Main(app.App):
|
||||||
if git_dir is None:
|
if git_dir is None:
|
||||||
log.error('Must have GIT_DIR set in enviroment')
|
log.error('Must have GIT_DIR set in enviroment')
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
os.chdir(git_dir)
|
|
||||||
os.environ['GIT_DIR'] = '.'
|
|
||||||
|
|
||||||
if hook == 'post-update':
|
if hook == 'post-update':
|
||||||
log.info('Running hook %s', hook)
|
log.info('Running hook %s', hook)
|
||||||
post_update(cfg)
|
post_update(cfg, git_dir)
|
||||||
log.info('Done.')
|
log.info('Done.')
|
||||||
else:
|
else:
|
||||||
log.warning('Ignoring unknown hook: %r', hook)
|
log.warning('Ignoring unknown hook: %r', hook)
|
||||||
|
|
Loading…
Reference in a new issue