Show More
@@ -27,8 +27,6 b' import os' | |||
|
27 | 27 | import shutil |
|
28 | 28 | import logging |
|
29 | 29 | import traceback |
|
30 | import pkg_resources | |
|
31 | from os.path import dirname as dn, join as jn | |
|
32 | 30 | from datetime import datetime |
|
33 | 31 | |
|
34 | 32 | from rhodecode.lib.vcs.backends import get_backend |
@@ -284,13 +282,15 b' class RepoModel(BaseModel):' | |||
|
284 | 282 | clone_uri) |
|
285 | 283 | log_create_repository(new_repo.get_dict(), |
|
286 | 284 | created_by=owner.username) |
|
287 | ||
|
285 | else: | |
|
286 | # install the githook if it's a git repo | |
|
287 | if repo_type == 'git': | |
|
288 | ScmModel().install_git_hook(repo=new_repo.scm_instance) | |
|
288 | 289 | # now automatically start following this repository as owner |
|
289 | 290 | ScmModel(self.sa).toggle_following_repo(new_repo.repo_id, |
|
290 | 291 | owner.user_id) |
|
291 | 292 | return new_repo |
|
292 | 293 | except: |
|
293 | print traceback.format_exc() | |
|
294 | 294 | log.error(traceback.format_exc()) |
|
295 | 295 | raise |
|
296 | 296 | |
@@ -448,6 +448,7 b' class RepoModel(BaseModel):' | |||
|
448 | 448 | :param clone_uri: |
|
449 | 449 | """ |
|
450 | 450 | from rhodecode.lib.utils import is_valid_repo, is_valid_repos_group |
|
451 | from rhodecode.model.scm import ScmModel | |
|
451 | 452 | |
|
452 | 453 | if parent: |
|
453 | 454 | new_parent_path = os.sep.join(parent.full_path_splitted) |
@@ -476,21 +477,7 b' class RepoModel(BaseModel):' | |||
|
476 | 477 | elif alias == 'git': |
|
477 | 478 | r = backend(repo_path, create=True, src_url=clone_uri, bare=True) |
|
478 | 479 | # add rhodecode hook into this repo |
|
479 | ||
|
480 | loc = jn(r.path, 'hooks') | |
|
481 | if not r.bare: | |
|
482 | loc = jn(r.path, '.git', 'hooks') | |
|
483 | if not os.path.isdir(loc): | |
|
484 | os.makedirs(loc) | |
|
485 | ||
|
486 | tmpl = pkg_resources.resource_string( | |
|
487 | 'rhodecode', jn('config', 'post_receive_tmpl.py') | |
|
488 | ) | |
|
489 | _hook_file = jn(loc, 'post-receive') | |
|
490 | with open(_hook_file, 'wb') as f: | |
|
491 | f.write(tmpl) | |
|
492 | os.chmod(_hook_file, 0755) | |
|
493 | ||
|
480 | ScmModel().install_git_hook(repo=r) | |
|
494 | 481 | else: |
|
495 | 482 | raise Exception('Undefined alias %s' % alias) |
|
496 | 483 |
@@ -23,14 +23,18 b'' | |||
|
23 | 23 | # You should have received a copy of the GNU General Public License |
|
24 | 24 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
25 | 25 | import os |
|
26 | import re | |
|
26 | 27 | import time |
|
27 | 28 | import traceback |
|
28 | 29 | import logging |
|
29 | 30 | import cStringIO |
|
31 | import pkg_resources | |
|
32 | from os.path import dirname as dn, join as jn | |
|
30 | 33 | |
|
31 | 34 | from sqlalchemy import func |
|
32 | 35 | from pylons.i18n.translation import _ |
|
33 | 36 | |
|
37 | import rhodecode | |
|
34 | 38 | from rhodecode.lib.vcs import get_backend |
|
35 | 39 | from rhodecode.lib.vcs.exceptions import RepositoryError |
|
36 | 40 | from rhodecode.lib.vcs.utils.lazy import LazyProperty |
@@ -545,3 +549,49 b' class ScmModel(BaseModel):' | |||
|
545 | 549 | choices.extend([x[0] for x in tags_group[0]]) |
|
546 | 550 | |
|
547 | 551 | return choices, hist_l |
|
552 | ||
|
553 | def install_git_hook(self, repo, force_create=False): | |
|
554 | """ | |
|
555 | Creates a rhodecode hook inside a git repository | |
|
556 | ||
|
557 | :param repo: Instance of VCS repo | |
|
558 | :param force_create: Create even if same name hook exists | |
|
559 | """ | |
|
560 | ||
|
561 | loc = jn(repo.path, 'hooks') | |
|
562 | if not repo.bare: | |
|
563 | loc = jn(repo.path, '.git', 'hooks') | |
|
564 | if not os.path.isdir(loc): | |
|
565 | os.makedirs(loc) | |
|
566 | ||
|
567 | tmpl = pkg_resources.resource_string( | |
|
568 | 'rhodecode', jn('config', 'post_receive_tmpl.py') | |
|
569 | ) | |
|
570 | ||
|
571 | _hook_file = jn(loc, 'post-receive') | |
|
572 | _rhodecode_hook = False | |
|
573 | log.debug('Installing git hook in repo %s' % repo) | |
|
574 | if os.path.exists(_hook_file): | |
|
575 | # let's take a look at this hook, maybe it's rhodecode ? | |
|
576 | log.debug('hook exists, checking if it is from rhodecode') | |
|
577 | _HOOK_VER_PAT = re.compile(r'^RC_HOOK_VER') | |
|
578 | with open(_hook_file, 'rb') as f: | |
|
579 | data = f.read() | |
|
580 | matches = re.compile(r'(?:%s)\s*=\s*(.*)' | |
|
581 | % 'RC_HOOK_VER').search(data) | |
|
582 | if matches: | |
|
583 | try: | |
|
584 | ver = matches.groups()[0] | |
|
585 | log.debug('got %s it is rhodecode' % (ver)) | |
|
586 | _rhodecode_hook = True | |
|
587 | except: | |
|
588 | log.error(traceback.format_exc()) | |
|
589 | ||
|
590 | if _rhodecode_hook or force_create: | |
|
591 | log.debug('writing hook file !') | |
|
592 | with open(_hook_file, 'wb') as f: | |
|
593 | tmpl = tmpl.replace('_TMPL_', rhodecode.__version__) | |
|
594 | f.write(tmpl) | |
|
595 | os.chmod(_hook_file, 0755) | |
|
596 | else: | |
|
597 | log.debug('skipping writing hook file') No newline at end of file |
General Comments 0
You need to be logged in to leave comments.
Login now