2 Perform gitosis actions for a git hook.
11 from ConfigParser
import NoSectionError
, NoOptionError
13 from gitosis
import repository
14 from gitosis
import ssh
15 from gitosis
import gitweb
16 from gitosis
import gitdaemon
17 from gitosis
import htaccess
18 from gitosis
import app
19 from gitosis
import util
20 from gitosis
import group
21 from gitosis
import serve
23 def autoinit_repos(config
):
25 do_init
= config
.getboolean('gitosis', 'init-on-config')
26 except (NoSectionError
, NoOptionError
):
32 for (section
, name
, topdir
, subpath
) in gitweb
.enum_cfg_repos(config
):
33 if os
.path
.exists(os
.path
.join(topdir
,subpath
)):
37 serve
.auto_init_repo(config
,topdir
,subpath
)
38 except GitInitError
, e
:
39 log
.warning('Auto-init failed: %r' % e
)
41 log
.warning('Git error in init: %r' % e
)
44 def post_update(cfg
, git_dir
):
45 export
= os
.path
.join(git_dir
, 'gitosis-export')
49 if e
.errno
== errno
.ENOENT
:
53 repository
.export(git_dir
=git_dir
, path
=export
)
55 os
.path
.join(export
, 'gitosis.conf'),
56 os
.path
.join(export
, '..', 'gitosis.conf'),
58 # re-read config to get up-to-date settings
59 cfg
.read(os
.path
.join(export
, '..', 'gitosis.conf'))
60 autoinit_repos(config
=cfg
)
61 gitweb
.set_descriptions(
64 generated
= util
.getGeneratedFilesDir(config
=cfg
)
65 gitweb
.generate_project_list(
67 path
=os
.path
.join(generated
, 'projects.list'),
69 gitdaemon
.set_export_ok(
72 if htaccess
.gen_htaccess_if_enabled(config
=cfg
):
73 group
.generate_group_list(
75 path
=os
.path
.join(generated
, 'groups'),
77 authorized_keys
= util
.getSSHAuthorizedKeysPath(config
=cfg
)
78 ssh
.writeAuthorizedKeys(
80 keydir
=os
.path
.join(export
, 'keydir'),
84 def create_parser(self
):
85 parser
= super(Main
, self
).create_parser()
86 parser
.set_usage('%prog [OPTS] HOOK')
87 parser
.set_description(
88 'Perform gitosis actions for a git hook')
91 def handle_args(self
, parser
, cfg
, options
, args
):
95 parser
.error('Missing argument HOOK.')
97 log
= logging
.getLogger('gitosis.run_hook')
100 git_dir
= os
.environ
.get('GIT_DIR')
102 log
.error('Must have GIT_DIR set in enviroment')
105 if hook
== 'post-update':
106 log
.info('Running hook %s', hook
)
107 post_update(cfg
, git_dir
)
110 log
.warning('Ignoring unknown hook: %r', hook
)