Show More
@@ -4,6 +4,8 b' import sys' | |||||
4 |
|
4 | |||
5 | try: |
|
5 | try: | |
6 | import rhodecode |
|
6 | import rhodecode | |
|
7 | RC_HOOK_VER = '_TMPL_' | |||
|
8 | os.environ['RC_HOOK_VER'] = RC_HOOK_VER | |||
7 | from rhodecode.lib.hooks import handle_git_post_receive |
|
9 | from rhodecode.lib.hooks import handle_git_post_receive | |
8 | except ImportError: |
|
10 | except ImportError: | |
9 | rhodecode = None |
|
11 | rhodecode = None | |
@@ -17,7 +19,7 b' def main():' | |||||
17 | sys.exit(0) |
|
19 | sys.exit(0) | |
18 |
|
20 | |||
19 | repo_path = os.path.abspath('.') |
|
21 | repo_path = os.path.abspath('.') | |
20 |
push_data = sys.stdin.read() |
|
22 | push_data = sys.stdin.readlines() | |
21 | # os.environ is modified here by a subprocess call that |
|
23 | # os.environ is modified here by a subprocess call that | |
22 | # runs git and later git executes this hook. |
|
24 | # runs git and later git executes this hook. | |
23 | # Environ get's some additional info from rhodecode system |
|
25 | # Environ get's some additional info from rhodecode system |
@@ -225,11 +225,13 b' def handle_git_post_receive(repo_path, r' | |||||
225 | init_model(engine) |
|
225 | init_model(engine) | |
226 |
|
226 | |||
227 | baseui = make_ui('db') |
|
227 | baseui = make_ui('db') | |
|
228 | # fix if it's not a bare repo | |||
|
229 | if repo_path.endswith('.git'): | |||
|
230 | repo_path = repo_path[:-4] | |||
228 | repo = Repository.get_by_full_path(repo_path) |
|
231 | repo = Repository.get_by_full_path(repo_path) | |
229 |
|
||||
230 | _hooks = dict(baseui.configitems('hooks')) or {} |
|
232 | _hooks = dict(baseui.configitems('hooks')) or {} | |
231 | # if push hook is enabled via web interface |
|
233 | # if push hook is enabled via web interface | |
232 | if _hooks.get(RhodeCodeUi.HOOK_PUSH): |
|
234 | if repo and _hooks.get(RhodeCodeUi.HOOK_PUSH): | |
233 |
|
235 | |||
234 | extras = { |
|
236 | extras = { | |
235 | 'username': env['RHODECODE_USER'], |
|
237 | 'username': env['RHODECODE_USER'], | |
@@ -242,18 +244,35 b' def handle_git_post_receive(repo_path, r' | |||||
242 | baseui.setconfig('rhodecode_extras', k, v) |
|
244 | baseui.setconfig('rhodecode_extras', k, v) | |
243 | repo = repo.scm_instance |
|
245 | repo = repo.scm_instance | |
244 | repo.ui = baseui |
|
246 | repo.ui = baseui | |
245 | old_rev, new_rev, ref = revs |
|
247 | ||
246 | if old_rev == EmptyChangeset().raw_id: |
|
248 | rev_data = [] | |
|
249 | for l in revs: | |||
|
250 | old_rev, new_rev, ref = l.split(' ') | |||
|
251 | _ref_data = ref.split('/') | |||
|
252 | if _ref_data[1] in ['tags', 'heads']: | |||
|
253 | rev_data.append({'old_rev': old_rev, | |||
|
254 | 'new_rev': new_rev, | |||
|
255 | 'ref': ref, | |||
|
256 | 'type': _ref_data[1], | |||
|
257 | 'name': _ref_data[2].strip()}) | |||
|
258 | ||||
|
259 | git_revs = [] | |||
|
260 | for push_ref in rev_data: | |||
|
261 | _type = push_ref['type'] | |||
|
262 | if _type == 'heads': | |||
|
263 | if push_ref['old_rev'] == EmptyChangeset().raw_id: | |||
247 | cmd = "for-each-ref --format='%(refname)' 'refs/heads/*'" |
|
264 | cmd = "for-each-ref --format='%(refname)' 'refs/heads/*'" | |
248 | heads = repo.run_git_command(cmd)[0] |
|
265 | heads = repo.run_git_command(cmd)[0] | |
249 | heads = heads.replace(ref, '') |
|
266 | heads = heads.replace(push_ref['ref'], '') | |
250 | heads = ' '.join(map(lambda c: c.strip('\n').strip(), |
|
267 | heads = ' '.join(map(lambda c: c.strip('\n').strip(), | |
251 | heads.splitlines())) |
|
268 | heads.splitlines())) | |
252 |
cmd = ('log ' |
|
269 | cmd = (('log %(new_rev)s' % push_ref) + | |
253 | ' --reverse --pretty=format:"%H" --not ' + heads) |
|
270 | ' --reverse --pretty=format:"%H" --not ' + heads) | |
254 | else: |
|
271 | else: | |
255 |
cmd = ('log ' |
|
272 | cmd = (('log %(old_rev)s..%(new_rev)s' % push_ref) + | |
256 | ' --reverse --pretty=format:"%H"') |
|
273 | ' --reverse --pretty=format:"%H"') | |
257 | git_revs = repo.run_git_command(cmd)[0].splitlines() |
|
274 | git_revs += repo.run_git_command(cmd)[0].splitlines() | |
|
275 | elif _type == 'tags': | |||
|
276 | git_revs += [push_ref['name']] | |||
258 |
|
277 | |||
259 | log_push_action(baseui, repo, _git_revs=git_revs) |
|
278 | log_push_action(baseui, repo, _git_revs=git_revs) |
General Comments 0
You need to be logged in to leave comments.
Login now