-
Notifications
You must be signed in to change notification settings - Fork 173
/
Copy pathpre-push
45 lines (35 loc) · 1019 Bytes
/
pre-push
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/env bash
# This pre-push hook should prevent pushing to the wrong remote
################
# Variables
################
declare -a authorized_remotes=(
'[email protected]:realm/realm-sync.git'
'https://github.com/realm/realm-sync.git'
'[email protected]:kspangsege/realm-sync.git'
'https://github.com/kspangsege/realm-sync.git'
)
repo_name='realm-sync'
################
# Functions
################
verify_remote() {
for current_authorized_remote in "${authorized_remotes[@]}"; do
if [[ "$1" = *"$current_authorized_remote"* ]]; then
return
fi
done
echo >&2 "attempting to push to a repo other than $repo_name or git remotes contains a repo other than $repo_name. aborting..."
exit 1
}
################
# Script
################
# current_remote_name="$1"
current_remote_url="$2"
verify_remote "$current_remote_url"
saved_remotes="$(git remote -v)"
while read -r remote_line; do
verify_remote "$remote_line"
done <<< "$saved_remotes"
exit 0