-
Notifications
You must be signed in to change notification settings - Fork 1
/
push_to_remotes.sh
executable file
·34 lines (31 loc) · 1.21 KB
/
push_to_remotes.sh
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
#!/bin/bash
# Push to all remotes of the given git repo and take special care for company remotes
# Also, possibly open according websites for reviews.
#
# author: andreasl
remotes_and_urls_str="$(git remote -v | grep '(push)')"
mapfile -t remotes_and_urls <<< "$remotes_and_urls_str"
for remote_and_url in "${remotes_and_urls[@]}"; do
remote="$(printf -- '%s' "$remote_and_url" | awk '{print $1}')"
if [[ "$remote_and_url" == *'code.wabo.run'* ]]; then
# push merge-request to company GitLab
local_branch="$(git rev-parse --abbrev-ref HEAD)"
if [[ "$local_branch" =~ ^master$|^main$ ]]; then
remote_branch="$(git log --oneline --format='%s' -n1 \
| sed -E 's/[^_a-zA-Z0-9-]+/-/g;s/^-+|-+$//g;s/./\L&/g')"
else
remote_branch="$local_branch"
fi
output="$(git push "$remote" HEAD:"$remote_branch" "$@" 2>&1)"
printf '%s' "$output"
if [[ "$output" == *' * [new branch] '* ]]; then
set -o pipefail
grep -E 'remote:[[:space:]]+http[s]*://' <<< "$output" \
| grep -o 'http.*$' \
| xargs xdg-open
fi
else
# default
git push "$remote" "$@"
fi
done