This is an automated email from the ASF dual-hosted git repository. nizhikov pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/ignite-extensions.git
commit 4be45b521f393bf0dcec5bd1dd085b4bd56269ce Author: samaitra <[email protected]> AuthorDate: Sat Dec 28 14:04:02 2019 -0600 adding scripts for applying pull requests --- scripts/apply-pull-request.sh | 220 +++++++++++++++++++++++++++++++++++++ scripts/git-format-patch.sh | 91 +++++++++++++++ scripts/git-patch-functions.sh | 131 ++++++++++++++++++++++ scripts/git-patch-prop.sh | 24 ++++ scripts/git-remoteless-branches.sh | 35 ++++++ scripts/update-versions.sh | 35 ++++++ 6 files changed, 536 insertions(+) diff --git a/scripts/apply-pull-request.sh b/scripts/apply-pull-request.sh new file mode 100755 index 0000000..ef27e52 --- /dev/null +++ b/scripts/apply-pull-request.sh @@ -0,0 +1,220 @@ +#!/bin/bash +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +# +# Pull request applier. +# + +# +# Start of Functions. +# + +# +# Prints usage. +# +usage () { + echo 'Usage: scripts/apply-pull-request.sh <pull-request-id> [-tb|--targetbranch <branch-name>]' + echo 'The script takes pull-request by given id and merges (with squash) all changes to target branch (master by default).' + echo "Argument 'pull-request-id' is mandatory." + echo "Target branch can be overwritten by using [-tb|--targetbranch <branch-name>] argument paramethers." +} + +# +# End of Functions. +# + +if [ "${GIT_HOME}" = "" ]; then + GIT_HOME="$(dirname "$(cd "$(dirname "$0")"; "pwd")")"; +fi + +cd ${GIT_HOME} + +if [ "${SCRIPTS_HOME}" = "" ]; then + SCRIPTS_HOME="${GIT_HOME}/scripts/" +fi + +. ${SCRIPTS_HOME}/git-patch-functions.sh # Import patch functions. + +PR_ID=$1 + +# +# Start reading of command line params. +# +if [ "${PR_ID}" = "" ]; then + echo $0", ERROR:" + echo >&2 "You have to specify 'pull-request-id'." + echo + usage + exit 1 +fi + +if [ "${PR_ID}" = "-h" ]; then + usage + exit 0 +fi + +if [ "${PR_ID}" = "--help" ]; then + usage + exit 0 +fi + + +while [[ $# > 2 ]] +do + key="$2" + + case $key in + -tb|--targetbranch) + TARGET_BRANCH="$3" + shift + ;; + + *) + echo "Unknown parameter: ${key}" + echo + usage + ;; + esac + shift +done +# +# Enf reading of command line params. +# + + +# Script variables. +if [ "${APACHE_GIT}" = "" ]; then + APACHE_GIT="https://gitbox.apache.org/repos/asf/ignite-extensions.git" +fi + +if [ "${GITHUB_MIRROR}" = "" ]; then + GITHUB_MIRROR="https://github.com/apache/ignite-extensions.git" +fi + +if [ "${TARGET_BRANCH}" = "" ]; then + TARGET_BRANCH="master" +fi + +requireCleanWorkTree ${GIT_HOME} + +CURRENT_BRANCH=`git rev-parse --abbrev-ref HEAD` + +if [ "$CURRENT_BRANCH" != "${TARGET_BRANCH}" ]; then + echo $0", ERROR:" + echo "You have to be on ${TARGET_BRANCH} branch." + + exit 1 +fi + +# Check that target branch is up-to-date. +APACHE_GIT_TARGET_BRANCH="apache-git-target-br-tmp" + +git fetch ${APACHE_GIT} ${TARGET_BRANCH}:${APACHE_GIT_TARGET_BRANCH} &> /dev/null +if test $? != 0; then + echo $0", ERROR:" + echo >&2 "Couldn't fetch '${TARGET_BRANCH}' branch from ${APACHE_GIT}." + exit 1 +fi + +LOCAL_TARGET_BR_HASH=$(git rev-parse @) +REMOTE_TARGET_BR_HASH=$(git rev-parse ${APACHE_GIT_TARGET_BRANCH}) +BASE_HASH=$(git merge-base @ ${APACHE_GIT_TARGET_BRANCH}) + +git branch -D ${APACHE_GIT_TARGET_BRANCH} &> /dev/null + +if [ $LOCAL_TARGET_BR_HASH != $REMOTE_TARGET_BR_HASH ]; then + echo $0", ERROR:" + + if [ $LOCAL_TARGET_BR_HASH = $BASE_HASH ]; then + echo "Your local ${TARGET_BRANCH} branch is not up-to-date. You need to pull." + elif [ $REMOTE_TARGET_BR_HASH = $BASE_HASH ]; then + echo "Your local ${TARGET_BRANCH} branch is ahead of ${TARGET_BRANCH} branch at Apache git. You need to push." + else + echo "Your local ${TARGET_BRANCH} and Apache git ${TARGET_BRANCH} branches diverged. You need to pull, merge and pull." + fi + + exit 1 +fi + +echo "Local ${TARGET_BRANCH} is Up-to-date." +echo + +# Checkout pull-request branch. +PR_BRANCH_NAME="pull-${PR_ID}-head" + +git fetch ${GITHUB_MIRROR} pull/${PR_ID}/head:${PR_BRANCH_NAME} &> /dev/null +if test $? != 0; then + echo $0", ERROR:" + echo >&2 "There was not found pull request by ID = '${PR_ID}'." + exit 1 +fi + +# Get author name number. +git checkout ${PR_BRANCH_NAME} &> /dev/null +if test $? != 0; then + echo $0", ERROR:" + echo >&2 "Failed to checkout '${PR_BRANCH_NAME}' branch (the branch not found or already exists)." + exit 1 +fi + +AUTHOR="$(git --no-pager show -s --format="%aN <%aE>" HEAD)" +ORIG_COMMENT="$(git log -1 --pretty=%B)" + +echo "Author of pull-request: '$AUTHOR'." +echo + +# Update local target branch. +git checkout ${TARGET_BRANCH} &> /dev/null + +# Take changes. +git merge --squash ${PR_BRANCH_NAME} &> /dev/null +if test $? != 0; then + git reset --hard &> /dev/null + + echo $0", ERROR:" + echo >&2 "Could not merge the pull-request to ${TARGET_BRANCH} without conflicts. All local changes have been discarded. You're on ${TARGET_BRANCH} branch." + exit 1 +fi + +echo "Original comment is" +echo "\"${ORIG_COMMENT}\"" +echo "Press [ENTER] if you're agree with the comment or type your comment and press [ENTER]:" +read COMMENT +echo + +if [ "${COMMENT}" == "" ]; then + COMMENT=${ORIG_COMMENT} +fi + +COMMENT="${COMMENT} - Fixes #${PR_ID}." + +if [ "${EXCLUDE_SPECIAL_FILE}" = "true" ]; then + git checkout HEAD ignite-pull-request-id +fi + +git commit --author "${AUTHOR}" -a -s -m "${COMMENT}" &> /dev/null + +echo "Squash commit for pull request with id='${PR_ID}' has been added. The commit has been added with comment '${COMMENT}'." +echo "Now you can review changes of the last commit at ${TARGET_BRANCH} and push it into ${APACHE_GIT} git after." +echo "If you want to decline changes, you can remove the last commit from your repo by 'git reset --hard HEAD^'." +echo + +# Clean-up. +git branch -D ${PR_BRANCH_NAME} &> /dev/null + +echo 'Successfully completed.' diff --git a/scripts/git-format-patch.sh b/scripts/git-format-patch.sh new file mode 100755 index 0000000..83aee3e --- /dev/null +++ b/scripts/git-format-patch.sh @@ -0,0 +1,91 @@ +#!/bin/bash +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +# +# Git patch-file maker. +# +echo 'Usage: scripts/git-format-patch.sh [-ih|--ignitehome <path>] [-idb|--ignitedefbranch <branch-name>] [-ph|--patchhome <path>]' +echo 'It is a script to create patch between Current branch (branch with changes) and Default branch. The script is safe and does not break or lose your changes.' +echo "It should be called from IGNITE_HOME directory." +echo "Patch will be created at PATCHES_HOME (= IGNITE_HOME, by default) between Default branch (IGNITE_DEFAULT_BRANCH) and Current branch." +echo "Note: you can use ${IGNITE_HOME}/scripts/git-patch-prop-local.sh to set your own local properties (to rewrite settings at git-patch-prop-local.sh). " +echo 'Examples:' +echo '- Basic (with all defaults and properties from git-patch-prop.sh): ./scripts/git-format-patch.sh' +echo '- Rewrite some defaults (see Usage): ./scripts/git-format-patch.sh -ph /home/user_name/patches' +echo + +# +# Init home and import properties and functions. +# +if [ -z ${IGNITE_HOME} ] # Script can be called from not IGNITE_HOME if IGNITE_HOME was set. + then IGNITE_HOME=$PWD +fi + +. ${IGNITE_HOME}/scripts/git-patch-prop.sh # Import properties. +. ${IGNITE_HOME}/scripts/git-patch-functions.sh # Import patch functions. + +if [ -f ${IGNITE_HOME}/scripts/git-patch-prop-local.sh ] # Whether a local user properties file exists. + then . ${IGNITE_HOME}/scripts/git-patch-prop-local.sh # Import user properties (it will rewrite global properties). +fi + +# +# Read command line params. +# +while [[ $# > 1 ]] +do + key="$1" + + case $key in + -ih|--ignitehome) + IGNITE_HOME="$2" + shift + ;; + + -idb|--ignitedefbranch) + IGNITE_DEFAULT_BRANCH="$2" + shift + ;; + + -ph|--patchhome) + PATCHES_HOME="$2" + shift + ;; + + *) + echo "Unknown parameter: ${key}" + ;; + esac + shift +done + +IGNITE_CURRENT_BRANCH=$( determineCurrentBranch ${IGNITE_HOME} ) + +echo "IGNITE_HOME : ${IGNITE_HOME}" +echo "Default branch : ${IGNITE_DEFAULT_BRANCH}" +echo "Current branch : ${IGNITE_CURRENT_BRANCH}" +echo +echo "PATCHES_HOME : ${PATCHES_HOME}" +echo + +# +# Main script logic. +# + +requireCleanWorkTree ${IGNITE_HOME} + +formatPatch ${IGNITE_HOME} ${IGNITE_DEFAULT_BRANCH} ${IGNITE_CURRENT_BRANCH} .patch diff --git a/scripts/git-patch-functions.sh b/scripts/git-patch-functions.sh new file mode 100644 index 0000000..cade691 --- /dev/null +++ b/scripts/git-patch-functions.sh @@ -0,0 +1,131 @@ +#!/bin/bash +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +# +# Git patch functions. +# + +# +# Define functions. +# + +# +# Formats patch. Create patch in one commit from user who run script and with default comment. +# +# Params: +# - Git home. +# - Default branch. +# - Patch with patch. +# - Suffix for created patch-file. +# +formatPatch () { + GIT_HOME=$1 + DEFAULT_BRANCH=$2 + PATCHED_BRANCH=$3 + PATCH_SUFFIX=$4 + + if [ ${IGNITE_CURRENT_BRANCH} = ${IGNITE_DEFAULT_BRANCH} ] + then + echo $0", ERROR:" + echo "You are on Default branch. Please, checkout branch with changes." + + exit 1 + fi + + cd ${GIT_HOME} + + git checkout ${DEFAULT_BRANCH} + + DEF_BRANCH_REV="$(git rev-parse --short HEAD)" + + git checkout -b tmppatch + + # Merge to make only one commit. + git merge --squash ${PATCHED_BRANCH} + git commit -a -m "# ${PATCHED_BRANCH}" + + PATCH_FILE=${PATCHES_HOME}'/'${DEFAULT_BRANCH}_${DEF_BRANCH_REV}_${PATCHED_BRANCH}${PATCH_SUFFIX} + + git format-patch ${DEFAULT_BRANCH} --stdout > ${PATCH_FILE} + echo "Patch file created." + + git checkout ${PATCHED_BRANCH} + + git branch -D tmppatch # Delete tmp branch. + + echo + echo "Patch created: ${PATCH_FILE}" +} + +# +# Determines Current branch. +# +# Params: +# - Git home. +# Return - Current branch. +# +determineCurrentBranch () { + GIT_HOME=$1 + + cd ${GIT_HOME} + + CURRENT_BRANCH=`git rev-parse --abbrev-ref HEAD` + + echo "$CURRENT_BRANCH" +} + +# +# Checks that given git repository has clean work tree (there is no uncommited changes). +# Exit with code 1 in error case. +# +# Params: +# - Git home. +# +requireCleanWorkTree () { + cd $1 # At git home. + + # Update the index + git update-index -q --ignore-submodules --refresh + err=0 + + # Disallow unstaged changes in the working tree + if ! git diff-files --quiet --ignore-submodules -- + then + echo $0", ERROR:" + echo >&2 "You have unstaged changes." + git diff-files --name-status -r --ignore-submodules -- >&2 + err=1 + fi + + # Disallow uncommitted changes in the index + if ! git diff-index --cached --quiet HEAD --ignore-submodules -- + then + echo $0", ERROR:" + echo >&2 "Your index contains uncommitted changes." + git diff-index --cached --name-status -r --ignore-submodules HEAD -- >&2 + err=1 + fi + + if [ $err = 1 ] + then + echo >&2 "Please commit or stash them." + exit 1 + fi +} + + diff --git a/scripts/git-patch-prop.sh b/scripts/git-patch-prop.sh new file mode 100644 index 0000000..1b531fa --- /dev/null +++ b/scripts/git-patch-prop.sh @@ -0,0 +1,24 @@ +#!/bin/bash +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +# +# Git patch-file maker/applier properties. +# +IGNITE_DEFAULT_BRANCH='master' + +PATCHES_HOME=${IGNITE_HOME} diff --git a/scripts/git-remoteless-branches.sh b/scripts/git-remoteless-branches.sh new file mode 100755 index 0000000..c712187 --- /dev/null +++ b/scripts/git-remoteless-branches.sh @@ -0,0 +1,35 @@ +#!/bin/bash +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +# Prints list of all local branches, which doesn't have remote. +# +# If '-d' argument passed it tries to delete found branches. +# Note that foreceful delete is used - so ANY UNMERGED CHANGES WILL BE LOST! +# +# Note this script doesn't inspect current branch. + +for branch in `git branch | grep -v "*"`; do + git branch -r | grep "$branch" > /dev/null + if [ "$?" == "1" ]; then + if [ "$1" == "-d" ]; then + git branch -D $branch + else + echo "$branch" + fi; + fi; +done; diff --git a/scripts/update-versions.sh b/scripts/update-versions.sh new file mode 100755 index 0000000..a9535c3 --- /dev/null +++ b/scripts/update-versions.sh @@ -0,0 +1,35 @@ +#!/bin/bash +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +# +# Updates Ignite version in Java pom files, .NET AssemblyInfo files, C++ configure files. +# Run in Ignite sources root directory. +# Usage: ./update-versions 2.6.0 +# + +if [ $# -eq 0 ] + then + echo "Version not specified" + exit 1 +fi + +echo Updating Java versions to $1 with Maven... +mvn versions:set -DnewVersion=$1 -Pall-java,all-scala,all-other -DgenerateBackupPoms=false -DgroupId=* -DartifactId=* -DoldVersion=* -DprocessDependencies=false + +echo Updating .NET & C++ versions to $1 with Maven... +mvn validate -P update-versions -D new.ignite.version=$1
