2016-06-19 03:10:45 +08:00
|
|
|
#!/bin/bash
|
|
|
|
#
|
|
|
|
# Copyright © 2016 Zetok Zalbavar <zetok@openmailbox.org>
|
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
|
|
|
|
# Source for bash functions used in `/{merge,test}-pr.sh`.
|
|
|
|
#
|
|
|
|
# Only to be sourced in those files.
|
|
|
|
|
|
|
|
set -e -o pipefail
|
|
|
|
|
2016-10-07 02:20:30 +08:00
|
|
|
# check if supplied var is a number; if not exit
|
2016-06-19 03:10:45 +08:00
|
|
|
is_pr_number() {
|
|
|
|
[[ "$@" =~ ^[[:digit:]]+$ ]]
|
|
|
|
}
|
|
|
|
|
|
|
|
exit_if_not_pr() {
|
|
|
|
is_pr_number $@ \
|
|
|
|
|| (echo "Not a PR number!" \
|
|
|
|
&& exit 1 )
|
|
|
|
}
|
|
|
|
|
|
|
|
# check if remote is present
|
|
|
|
is_remote_present() {
|
|
|
|
git remote \
|
|
|
|
| grep $@ > /dev/null
|
|
|
|
}
|
|
|
|
|
2016-08-04 06:25:50 +08:00
|
|
|
# there's no qTox remote, add it
|
2016-06-19 03:10:45 +08:00
|
|
|
# if `https` is supplied, https version of repo is used
|
|
|
|
add_remote() {
|
2016-08-04 06:25:50 +08:00
|
|
|
local remote_url="git@github.com:qTox/qTox.git"
|
2016-06-19 03:10:45 +08:00
|
|
|
local remote_name="upstream"
|
|
|
|
|
|
|
|
# change to https if needed
|
|
|
|
[[ "$@" == "https" ]] \
|
2016-08-04 06:25:50 +08:00
|
|
|
&& local remote_url="https://github.com/qTox/qTox.git"
|
2016-06-19 03:10:45 +08:00
|
|
|
|
|
|
|
is_remote_present $remote_name \
|
|
|
|
|| git remote add $remote_name "${remote_url}"
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
# print the message only if the merge was successful
|
|
|
|
#
|
|
|
|
# supply either `merge`, `test` or whatever else merge branch name you want
|
|
|
|
after_merge_msg() {
|
|
|
|
echo ""
|
|
|
|
echo "PR #$PR was merged into «$@$PR» branch."
|
2019-09-15 03:19:18 +08:00
|
|
|
echo "To compare with $base_branch:"
|
2016-06-19 03:10:45 +08:00
|
|
|
echo ""
|
2019-09-15 03:19:18 +08:00
|
|
|
echo " git diff $base_branch..$@$PR"
|
2016-06-19 03:10:45 +08:00
|
|
|
echo ""
|
|
|
|
if [[ "$@" == "merge" ]]
|
|
|
|
then
|
2019-09-15 03:19:18 +08:00
|
|
|
echo "To push that to $base_branch on github:"
|
2016-06-19 03:10:45 +08:00
|
|
|
echo ""
|
2019-09-15 03:19:18 +08:00
|
|
|
echo " git checkout $base_branch && git merge --ff $@$PR && git push upstream $base_branch"
|
2016-06-19 03:10:45 +08:00
|
|
|
echo ""
|
2019-09-15 03:19:18 +08:00
|
|
|
echo "After pushing to $base_branch, delete branches:"
|
2016-06-19 03:10:45 +08:00
|
|
|
echo ""
|
|
|
|
echo " git branch -d {$@,}$PR"
|
|
|
|
echo ""
|
|
|
|
fi
|
|
|
|
echo "To discard any changes:"
|
|
|
|
echo ""
|
2019-09-15 03:19:18 +08:00
|
|
|
echo " git checkout $base_branch && git branch -D {$@,}$PR"
|
2016-06-19 03:10:45 +08:00
|
|
|
echo ""
|
|
|
|
}
|
|
|
|
|
|
|
|
# print the message only if some merge step failed
|
|
|
|
after_merge_failure_msg() {
|
|
|
|
echo ""
|
|
|
|
echo "Merge failed."
|
|
|
|
echo ""
|
|
|
|
echo "You may want to remove not merged branches, if they exist:"
|
|
|
|
echo ""
|
2019-09-15 03:19:18 +08:00
|
|
|
echo " git checkout $base_branch && git branch -D {$@,}$PR"
|
2016-06-19 03:10:45 +08:00
|
|
|
echo ""
|
|
|
|
}
|
|
|
|
|
2016-10-07 02:20:30 +08:00
|
|
|
# force delete merged and fetched branches
|
|
|
|
rm_obsolete_branch() {
|
|
|
|
git branch -D {$merge_branch,}$PR 2>/dev/null || true
|
|
|
|
}
|
2016-06-19 03:10:45 +08:00
|
|
|
|
|
|
|
get_sources() {
|
|
|
|
add_remote
|
2016-10-07 02:20:30 +08:00
|
|
|
rm_obsolete_branch
|
2016-06-19 03:10:45 +08:00
|
|
|
git fetch $remote_name pull/$PR/head:$PR && \
|
2019-09-15 03:19:18 +08:00
|
|
|
git checkout $base_branch -b $merge_branch$PR
|
2016-06-19 03:10:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
# check whether to sign
|
|
|
|
merge() {
|
2016-07-13 02:47:49 +08:00
|
|
|
"${@}" --no-ff $PR -m "Merge pull request #$PR
|
2016-07-05 00:49:59 +08:00
|
|
|
$OPT_MSG
|
2019-09-15 03:19:18 +08:00
|
|
|
$(git shortlog $base_branch..$PR)"
|
2016-06-19 03:10:45 +08:00
|
|
|
}
|