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