#7300 Deny push / Implement git hook for unescaped macro in %changelog
Closed: Can't Fix 4 years ago by syeghiay. Opened 6 years ago by ignatenkobrain.

#!/usr/bin/python3
import re
import sys

replace = False
out = []
with open(sys.argv[1], "r") as f:
    for l in f:
        out.append(l)
        if l.startswith("%changelog"):
            replace = True
            continue
        if not replace:
            continue
        if l.startswith("%"):
            replace = False
            continue
        if l.startswith("*"):
            # XXX: HACK
            continue
        out[-1] = re.sub(r"([^%])%([^% \n\d])", r"\1%%\2", l)

with open(sys.argv[1], "w") as f:
    f.writelines(out)

This is something I've been using for automatic fix myself. I think we should either prohibit pushing this or have git-hook which would fix it automatically.


I'd go for the preventing the push just because it's potentially less error-prone to have a human apply the fix.

I'm not sure fixing by server-side hook is even possible, so +1 for push reject here.

Why if l.startswith("*"): continue? This is very likely to be an error too, e.g.:

dracut/dracut.spec
1385:* Fri May 20 2011 Harald Hoyer harald@redhat.com 011-0.1%{?rdist}

... I'd rather see a whitelist of macros allowed in the changelog, if there are any that can be legitimately used.

I guess there already is some pre-receive hook in each rpm repo. So here [1] is possible
script which could be run like ./no-macro-in-changelog test.spec oldhash newhash. For local
testing, there's also pre-receive hook.

[1] https://github.com/praiskup/pre-receive-hooks

Sorry but this can't be fixed at this time.

Metadata Update from @syeghiay:
- Issue close_status updated to: Can't Fix
- Issue status updated to: Closed (was: Open)

4 years ago

Login to comment on this ticket.

Metadata