Mercurial > kallithea
changeset 6009:e54ddaa52fee
hooks: parse incoming git refs correctly
Hooks receive a line of the following format on standard input:
<old-value> SP <new-value> SP <ref-name> LF
where <old-value> is the old object name stored in the ref,
<new-value> is the new object name to be stored in the ref
and <ref-name> is the full name of the ref.
This means, we have to strip at least the LF in order to have a
correct version of the ref name after the split. Also, when
parsing the ref name itself, use all components but first instead
of just second, as a ref name may have slashes in it.
Previously, failure to parse ref name correctly would lead to the
following behaviour. A newly created repository with no commits pushed
has HEAD set to refs/heads/master by default, even though there's no
such ref in the repository yet. Upon first push, Kallithea rewrites
this symbolic reference with a reference to a real branch.
However, due to a bug in ref name parsing, if a ref name had a slash,
Kallithea would update HEAD to an invalid reference:
git push origin feature/branch
would rewrite HEAD to refs/heads/feature. All future attempts to work
with this repository would fail because dulwich would complain it can't
read HEAD as it is a directory.
author | Andrew Shadura <andrew@shadura.me> |
---|---|
date | Sun, 24 Jul 2016 18:12:14 +0200 |
parents | bcb807305731 |
children | 5d524b9246d8 |
files | kallithea/lib/hooks.py |
diffstat | 1 files changed, 2 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/kallithea/lib/hooks.py Thu Jul 14 14:47:38 2016 +0200 +++ b/kallithea/lib/hooks.py Sun Jul 24 18:12:14 2016 +0200 @@ -424,14 +424,14 @@ elif hook_type == 'post' and _hooks.get(Ui.HOOK_PUSH): rev_data = [] for l in revs: - old_rev, new_rev, ref = l.split(' ') + old_rev, new_rev, ref = l.strip().split(' ') _ref_data = ref.split('/') if _ref_data[1] in ['tags', 'heads']: rev_data.append({'old_rev': old_rev, 'new_rev': new_rev, 'ref': ref, 'type': _ref_data[1], - 'name': _ref_data[2].strip()}) + 'name': '/'.join(_ref_data[2:])}) git_revs = []