summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorrl1987 <rl1987@sdf.lonestar.org>2019-02-20 19:48:52 +0200
committerDavid Goulet <dgoulet@torproject.org>2019-03-05 14:26:09 -0500
commitf3eac74ed9c68212a9df1a1acbdf146662469a5a (patch)
treed07ee7c7bb20268d55a041bdb2564a3022273b58 /scripts
parentae5a0f39cd3d0098ca684c7dfb83ebfe3acca8b6 (diff)
downloadtor-f3eac74ed9c68212a9df1a1acbdf146662469a5a.tar.gz
tor-f3eac74ed9c68212a9df1a1acbdf146662469a5a.zip
In pre-push hook script, actually check local and remote refs
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/maint/pre-push.git-hook38
1 files changed, 21 insertions, 17 deletions
diff --git a/scripts/maint/pre-push.git-hook b/scripts/maint/pre-push.git-hook
index 78d62527e0..14bc0690c1 100755
--- a/scripts/maint/pre-push.git-hook
+++ b/scripts/maint/pre-push.git-hook
@@ -11,29 +11,20 @@
# The following sample script was used as starting point:
# https://github.com/git/git/blob/master/templates/hooks--pre-push.sample
+echo "Running pre-push hook"
+
z40=0000000000000000000000000000000000000000
remote="$1"
-CUR_BRANCH=$(git rev-parse --abbrev-ref HEAD)
-# Only allow pushing master, release-* and maint-* branches to origin.
-if [ "$remote" == "origin" ]
-then
- if [ "$CUR_BRANCH" != "master" ] && [[ $CUR_BRANCH != release-* ]] &&
- [[ $CUR_BRANCH != maint-* ]]
+ref_is_upstream_branch() {
+ if [ "$1" == "refs/heads/master" ] ||
+ [[ "$1" == refs/heads/release-* ]] ||
+ [[ "$1" == refs/heads/maint-* ]]
then
- echo >&2 "Not pushing $CUR_BRANCH to origin"
- exit 1
+ return 1
fi
-fi
-
-if [ "$CUR_BRANCH" != "master" ] && [[ $CUR_BRANCH != release-* ]] &&
- [[ $CUR_BRANCH != maint-* ]]
-then
- exit 0
-fi
-
-echo "Running pre-push hook"
+}
# shellcheck disable=SC2034
while read -r local_ref local_sha remote_ref remote_sha
@@ -52,6 +43,19 @@ do
range="$remote_sha..$local_sha"
fi
+ if ref_is_upstream_branch "$local_ref" == 0 ||
+ ref_is_upstream_branch "$remote_ref" == 0
+ then
+ if [ "$remote" == "origin" ]
+ then
+ echo >&2 "Not pushing: $local_ref to $remote_ref"
+ echo >&2 "If you really want to push this, use --no-verify."
+ exit 1
+ else
+ continue
+ fi
+ fi
+
# Check for fixup! commit
commit=$(git rev-list -n 1 --grep '^fixup!' "$range")
if [ -n "$commit" ]