From b41e353f78ddc1b67f7fad77c5a8b10503558a58 Mon Sep 17 00:00:00 2001 From: Misty Stanley-Jones Date: Tue, 14 Oct 2014 12:48:27 +1000 Subject: [PATCH] HBASE-12249 Script to help you adhere to the patch-naming guidelines --- dev-support/make_patch.sh | 97 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100755 dev-support/make_patch.sh diff --git a/dev-support/make_patch.sh b/dev-support/make_patch.sh new file mode 100755 index 0000000..7ecef6e --- /dev/null +++ b/dev-support/make_patch.sh @@ -0,0 +1,97 @@ +#!/bin/bash + +patch_dir=~/patches +# Make a patch for the current branch based on its tracking branch + +if [[ $1 == '-h' ]]; then + echo "Usage: $0 [-h] - display these instructions." + echo "Usage: $0 [-a] - Add an 'addendum' prefix to the patch name." + echo "Edit $0 to set the patch directory." +elif [[ $1 == '-a' ]]; then + addendum='-addendum' +fi + +# Find what branch we are on +branch=$(git branch |grep '*' |awk '{print $2}') +if [ ! $branch ]; then + echo "Can't determine the git branch. Exiting." + exit 1 +fi + +# Determine the tracking branch +git log -n 1 origin/$branch > /dev/null 2>&1 +status=$? +if [ $status == 128 ]; then + # Status 128 means there is no remote branch + tracking_branch='origin/master' +elif [ $status == 0 ]; then + # Status 0 means there is a remote branch + tracking_branch="origin/$branch" +else + echo "Unknown error: $?" + exit 1 +fi + +# Determine what to call the patch +# Check to see if any patch exists that includes the branch name +status=$(ls $patch_dir/*$branch* 2>/dev/null|grep -v addendum|wc -l|awk {'print $1'}) +if [ $status == 0 ]; then + # This is the first patch we are making for this release + prefix='' +elif [ $status -ge 1 ]; then + # At least one patch already exists -- add a version prefix + for i in {1..99} + do + # Check to see the maximum version of patch that exists + if [ ! -f "$patch_dir/$branch-v$i.patch" ]; then + version=$i + if [ ! -z $addendum ]; then + # Don't increment the patch # if it is an addendum + echo "Creating an addendum" + if [[ $version == 1 ]]; then + # We are creating an addendum to the first version of the patch + prefix='' + else + # We are making an addendum to a different version of the patch + let version=$version-1 + prefix="-v$version" + fi + else + prefix="-v$version" + fi + break + fi + done +fi + +patch_name="$branch$prefix$addendum.patch" + +# Do we need to make a diff? +git diff --quiet $tracking_branch +status=$? +if [[ $status == 0 ]]; then + echo "There is no difference between $branch and $tracking_branch." + echo "No patch created." + exit 0 +fi + +# Check whether we need to squash or not +local_commits=$(git log $tracking_branch..$branch|grep 'Author:'|wc -l|awk {'print $1'}) +if [[ $local_commits > 1 ]]; then + read -p "$local_commits commits exist only in your local branch. Interactive rebase?" yn + case $yn in + [Yy]* ) + git rebase -i $tracking_branch + ;; + [Nn]* ) + echo "Creating $patch_dir/$patch_name using git diff." + git diff $tracking_branch > $patch_dir/$patch_name + exit 0 + ;; + esac +fi + +echo "Creating patch $patch_dir/$patch_name using git format-patch" +git format-patch --stdout $tracking_branch > $patch_dir/$patch_name + + -- 2.1.2