File tree Expand file tree Collapse file tree 1 file changed +40
-0
lines changed Expand file tree Collapse file tree 1 file changed +40
-0
lines changed Original file line number Diff line number Diff line change
1
+ #! /usr/bin/env bash
2
+
3
+ zero_commit=" 0000000000000000000000000000000000000000"
4
+
5
+ # This example allows force pushes for branches named scratch/* and test/*
6
+ force_push_prefix="
7
+ scratch
8
+ test
9
+ "
10
+
11
+ is_force_push () {
12
+ # If this is a new branch there's no history to overwrite
13
+ if [[ ${oldrev} == ${zero_commit} ]]; then
14
+ return 1
15
+ fi
16
+
17
+ if git merge-base --is-ancestor ${oldrev} ${newrev} ; then
18
+ return 1
19
+ else
20
+ return 0
21
+ fi
22
+ }
23
+
24
+ while read -r oldrev newrev refname; do
25
+ if is_force_push; then
26
+ force_push_permitted=false
27
+ for push_prefix in ${force_push_prefix} ; do
28
+ if [[ ${refname} == " refs/heads/${push_prefix} /" * ]]; then
29
+ force_push_permitted=true
30
+ break
31
+ fi
32
+ done
33
+ if [[ ${force_push_permitted} == true ]]; then
34
+ continue
35
+ else
36
+ echo " force push detected in restricted branch ${refname} "
37
+ exit 1
38
+ fi
39
+ fi
40
+ done
You can’t perform that action at this time.
0 commit comments