2016-03-22 02:02:01 +08:00
|
|
|
|
#!/bin/bash
|
|
|
|
|
#
|
|
|
|
|
# Copyright © 2016 Zetok Zalbavar
|
|
|
|
|
#
|
|
|
|
|
# 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/>.
|
|
|
|
|
|
|
|
|
|
# Script for merging pull requests. Works only when there are no merge
|
|
|
|
|
# conflicts. Assumes that working dir is a qTox git repo.
|
|
|
|
|
#
|
|
|
|
|
# Requires SSH key that github accepts and GPG set to sign merge commits.
|
|
|
|
|
|
|
|
|
|
# usage:
|
2016-03-22 22:12:13 +08:00
|
|
|
|
# ./$script $pr_number $optional_message
|
|
|
|
|
#
|
|
|
|
|
#
|
|
|
|
|
# $pr_number – number of the PR as shown on GH
|
|
|
|
|
# $optional_message – message that is going to be put in merge commit,
|
|
|
|
|
# before the appended shortlog.
|
|
|
|
|
#
|
2016-03-22 02:02:01 +08:00
|
|
|
|
|
|
|
|
|
PR=$1
|
|
|
|
|
|
2016-03-22 22:12:13 +08:00
|
|
|
|
# make sure to add newlines to the message, otherwise merge message
|
|
|
|
|
# will not look well
|
|
|
|
|
if [[ ! -z $2 ]]
|
|
|
|
|
then
|
|
|
|
|
OPT_MSG="
|
|
|
|
|
$2
|
|
|
|
|
"
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
2016-03-29 08:03:17 +08:00
|
|
|
|
# check if supplied var is a number; if not exit
|
|
|
|
|
if [[ ! "${PR}" =~ ^[[:digit:]]+$ ]]
|
|
|
|
|
then
|
|
|
|
|
echo "Not a PR number!" && \
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
2016-03-22 02:02:01 +08:00
|
|
|
|
|
|
|
|
|
# list remotes, and if there's no tux3 one, add it
|
2016-03-29 08:03:17 +08:00
|
|
|
|
if ! git remote | grep upstream > /dev/null
|
2016-03-22 02:02:01 +08:00
|
|
|
|
then
|
2016-03-29 08:03:17 +08:00
|
|
|
|
git remote add upstream git@github.com:tux3/qTox.git
|
2016-03-22 02:02:01 +08:00
|
|
|
|
fi
|
|
|
|
|
|
2016-03-22 22:12:13 +08:00
|
|
|
|
# print the message only if the merge was successful
|
|
|
|
|
after_merge_msg() {
|
|
|
|
|
echo ""
|
|
|
|
|
echo "PR #$PR was merged into «merge$PR» branch."
|
|
|
|
|
echo "To compare with master:"
|
2016-05-15 19:59:02 +08:00
|
|
|
|
echo ""
|
|
|
|
|
echo " git diff master..merge$PR"
|
2016-03-22 22:12:13 +08:00
|
|
|
|
echo ""
|
|
|
|
|
echo "To push that to master on github:"
|
2016-05-15 19:59:02 +08:00
|
|
|
|
echo ""
|
|
|
|
|
echo " git checkout master && git merge --ff merge$PR && git push upstream master"
|
2016-03-22 22:12:13 +08:00
|
|
|
|
echo ""
|
|
|
|
|
echo "After pushing to master, delete branches:"
|
|
|
|
|
echo ""
|
2016-05-15 19:59:02 +08:00
|
|
|
|
echo " git branch -d {merge,}$PR"
|
|
|
|
|
echo ""
|
|
|
|
|
echo "To discard any changes:"
|
|
|
|
|
echo ""
|
|
|
|
|
echo " git checkout master && git branch -D {merge,}$PR"
|
|
|
|
|
echo ""
|
2016-03-22 22:12:13 +08:00
|
|
|
|
}
|
|
|
|
|
|
2016-03-29 08:03:17 +08:00
|
|
|
|
# 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 ""
|
2016-05-15 19:59:02 +08:00
|
|
|
|
echo " git checkout master && git branch -D {merge,}$PR"
|
|
|
|
|
echo ""
|
2016-03-29 08:03:17 +08:00
|
|
|
|
}
|
|
|
|
|
|
2016-03-22 22:12:13 +08:00
|
|
|
|
|
2016-03-29 08:03:17 +08:00
|
|
|
|
git fetch upstream && \
|
2016-03-22 02:02:01 +08:00
|
|
|
|
git checkout master && \
|
2016-03-29 08:03:17 +08:00
|
|
|
|
git rebase upstream/master master && \
|
|
|
|
|
git fetch upstream pull/$PR/head:$PR && \
|
2016-03-22 02:02:01 +08:00
|
|
|
|
git checkout master -b merge$PR && \
|
|
|
|
|
git merge --no-ff -S $PR -m "Merge pull request #$PR
|
2016-03-22 22:12:13 +08:00
|
|
|
|
$OPT_MSG
|
2016-03-22 02:02:01 +08:00
|
|
|
|
$(git shortlog master..$PR)" && \
|
2016-03-29 08:03:17 +08:00
|
|
|
|
after_merge_msg || after_merge_failure_msg
|