Skip to content

Commit eed2462

Browse files
committed
update serverhooks/update
1 parent c2ef4d5 commit eed2462

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

serverhooks/update

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
# and the SHA-1 the user is trying to push. If the update script exits non-zero, only that
1515
# reference is rejected; other references can still be updated.
1616

17-
refname=$1
18-
oldrev=$2
19-
newrev=$3
17+
refname=$1 # name of ref that is being updated
18+
oldrev=$2 # old object name that ref pointed to before
19+
newrev=$3 # new object name that ref should point to
2020
echo "Enforcing policies for revision ${refname}:"
2121

2222
# -------------------------------
@@ -30,10 +30,14 @@ fi
3030

3131
# Check if a zero sha, then either a new branch is pushed or an empty repo is being pushed
3232
if [ "${oldrev}" == "0000000000000000000000000000000000000000" ]; then
33-
# List everything reachable from newrev but not any heads
34-
span=`git rev-list $(git for-each-ref --format='%(refname)' refs/heads/* | sed 's/^/\^/') ${newrev}`
33+
# List heads, add a ^ to negate in the following 'git rev-list' command
34+
heads=$(git for-each-ref --format='%(refname)' refs/heads/* | sed 's/^/\^/')
35+
# List everything reachable from ${newref} but not from any heads
36+
span=$(git rev-list ${newrev} ${heads})
3537
else
36-
span=`git rev-list ${oldrev}..${newrev}`
38+
# branch labels are updated after hook ran successfully, so get all new commits, but none that are reachable from any branches
39+
# specify that we don’t want any commits that are reachable from any of the known branch labels
40+
span=$(git rev-list ${oldrev}..${newrev} --not --branches='*')
3741
fi
3842

3943
# ------------------------------------

0 commit comments

Comments
 (0)