Skip to content

Commit bee1a3c

Browse files
committed
Access controls for new refs and merges
Disallow receiving merge commits. Only allow new refs from users listed in hooks.branchers.
1 parent e12973a commit bee1a3c

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

githooks/update

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,12 @@ def check_committer(rev, expected):
136136
rev)
137137

138138

139+
def check_merge(rev):
140+
parents = run(['git', 'show', '-s', '--format=%P', rev])[0].split()
141+
if len(parents) > 1:
142+
fatal('Merge commits are not allowed')
143+
144+
139145
refname, oldrev, newrev = sys.argv[1:]
140146

141147
# Look up username in the authors file.
@@ -155,13 +161,19 @@ if not expected_committer:
155161
if newrev == no_rev:
156162
fatal('Deleting refs is not allowed')
157163

164+
branchers = run(['git', 'config', '--get-all', 'hooks.branchers'])
165+
if oldrev == no_rev:
166+
if user not in branchers:
167+
fatal('User %s not authorized to create new refs' % user)
168+
158169
if refname.startswith('refs/heads/'):
159170
# receive.denyNonFastForwards will prevent non-ff updates.
160171
for rev in run(['git', 'rev-list', newrev, '--not', '--all'])[::-1]:
161172
msg = run(['git', 'show', '-s', '--format=%B', rev])
162173
check_message(rev, msg)
163174
check_whitespace(rev, msg)
164175
check_committer(rev, expected_committer)
176+
check_merge(rev)
165177
elif refname.startswith('refs/tags/'):
166178
if oldrev != no_rev:
167179
fatal('Changing tags is not allowed')

0 commit comments

Comments
 (0)