diff --git a/dev-support/rebase_all_git_branches.sh b/dev-support/rebase_all_git_branches.sh new file mode 100755 index 0000000..13cb779 --- /dev/null +++ b/dev-support/rebase_all_git_branches.sh @@ -0,0 +1,117 @@ +#!/bin/bash + +# Licensed 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. + +# This script assumes that your remote is called "origin" +# and that your local master branch is called "master". +# I am sure it could be made more abstract but these are the defaults. + +# Edit this line to point to your default directory, +# or always pass a directory to the script. + +DEFAULT_DIR=EDIT_ME + +if [[ $1 == '-h' ]]; then + # Print usage instructions + echo "Usage:" + echo "Rebase all branches in HBase directory: $0" + echo "Rebase all branches in a given directory: $0 " + exit +fi + +# Figure out the directory of our Git repo +if [ -n $1 ]; then + # A specific directory was passed in + dir=$1 +else + # Default to rebasing the hbase directory + dir=$DEFAULT_DIR + if [[ $DEFAULT_DIR == 'EDIT_ME' ]]; then + echo "You need to edit the DEFAULT_DIR in $0. Exiting." + exit 1 + elif [[ ! -d $DEFAULT_DIR ]]; then + echo "Directory $DEFAULT_DIR does not exist. Exiting." + exit 1 + fi +fi + +# Store the old directory +olddir=`pwd` + +cd $dir + +# For each tracking branch, check it out and make sure it's fresh +git branch -lvv | grep "\[origin/"|sed -e 's/\*//g'|awk {'print $1'} |while read i; +do + git checkout -q $i + git pull -q --rebase + status=$? + if [ $status != 0 ]; then + echo "Unable to pull changes in $i: $status Exiting." + exit 1 + fi + echo "Refreshed $i from remote." +done + +for i in `git branch --list|sed -e "s/\*//g"`; do + # Check JIRA status to see if we still need this branch + if [[ $i == HBASE-* ]] || [[ $i == hbase-* ]]; then + jira=$(echo $i |awk '{print toupper($0)}') + jira_url='https://issues.apache.org/jira/browse' + # The JIRA status looks like this in the HTML: + # span id="resolution-val" class="value resolved" > + # The following is a bit brittle, but matches lines with + # resolution-val and gets the 'resolved' (or unresolved) part + jira_status=$(curl -s $jira_url/$jira|grep resolution-val|sed -e "s/.*class=\"value\ //"|cut -d'"' -f 1) + if [[ $jira_status == 'resolved' ]]; then + # the JIRA seems to be resolved or is at least not unresolved + #echo "$i is resolved. Delete manually: git branch -D $i" + deleted_branches="$i $deleted_branches" + fi + fi + + git checkout -q $i + # If this branch has a remote, don't rebase it + # If it has a remote, it has a log with at least one entry + git log -n 1 origin/$i > /dev/null 2>&1 + status=$? + if [ $status == 128 ]; then + # Status 128 means there is no remote branch + # Try to rebase + echo "Rebasing $i on origin/master" + git rebase -q origin/master > /dev/null 2>&1 + if [ $? -ne 0 ]; then + echo "Failed. Rolling back. Rebase $i manually." + git rebase --abort + #else + #echo "Making a patch: $i-migration.patch" + #git diff --no-prefix origin/master > git-migration/$i-migration.patch + fi + elif [ $status == 0 ]; then + # Status 0 means there is a remote branch -- we already took care of these + break + else + echo "Unknown error: $?" + fi +done + +# Offer to clean up all deleted branches +if [[ $deleted_branches ]]; then + echo "Deleted branches: $deleted_branches" + read -p "Delete them? " yn + case $yn in + [Yy]* ) git branch -D $deleted_branches;; + * ) echo -e "To delete them manually, issue the following command:\n git branch -D $deleted_branches";; + esac +fi +cd $olddir \ No newline at end of file diff --git a/src/main/docbkx/developer.xml b/src/main/docbkx/developer.xml index 382367f..ecad273 100644 --- a/src/main/docbkx/developer.xml +++ b/src/main/docbkx/developer.xml @@ -1780,6 +1780,37 @@ justification="I know what I'm doing") +
+ Git Best Practices + + + Use the correct method to create patches. See . + + + Avoid git merges. Use git pull --rebase or git + fetch followed by git rebase. + + + Do not use git push --force. If the push does not work, fix + the problem or ask for help. + + + Please contribute to this document if you think of other Git best + practices. +
+ <code>rebase_all_git_branches.sh</code> + The dev-support/rebase_all_git_branches.sh script is + provided to help keep your Git repository clean. Use the -h + parameter to get usage instructions. The script automatically refreshes your + tracking branches, attempts an automatic rebase of each local branch against its + parent branch, and gives you the option to delete any branch which represents a + closed JIRA. The script has one optional configuration option, the location of + your Git directory, which you can set by editing the script. Otherwise, you can + pass the git directory manually as an absolute or relative file path (even + . works). +
+
Submitting Patches @@ -1787,7 +1818,8 @@ justification="I know what I'm doing") contribute patches in our new GIT context, caveat the fact that we have a different branching model and that we don't currently do the merge practice described in the following, the accumulo doc - on how to contribute and develop after our move to GIT is worth a read. + on how to contribute and develop after our move to GIT is worth a read. + See also . If you are new to submitting patches to open source or new to submitting patches to Apache, start by reading the