Skip to content

Instantly share code, notes, and snippets.

@Amwam
Last active August 29, 2015 14:05
Show Gist options
  • Save Amwam/b4f1ec9dea1a75f04faa to your computer and use it in GitHub Desktop.
Save Amwam/b4f1ec9dea1a75f04faa to your computer and use it in GitHub Desktop.
Show the status of all branches in relation to master and develop
#!/bin/bash
#
# script will clone a git repository into a temporary working directory
# where it will analyse branches that contains the word 'feature'
# comparing them to master and develop to determine the number of
# commits in the feature that are not yet merged with develop
# and the number of commits in master that are not yet merged with the feature.
START_DIR=`pwd`
WORKING_DIR="$HOME/.gitanalyse-`date +%s`"
REPORT_LOC="${WORKING_DIR}/report.html"
LOCAL_REPO="${WORKING_DIR}/local-repo"
GIT_CLONE_LOG="${WORKING_DIR}/clone.log"
function usage() {
echo "Usage: $0 \"http://path/to/repo.git\""
}
function create_working_dir() {
mkdir $WORKING_DIR
cd $WORKING_DIR
}
function clean_working_dir() {
cd $START_DIR
rm -rf $WORKING_DIR
}
function _check_branch_against_branch() {
git cherry $1 $2 | wc -l | sed s/' '//g
}
if [[ "x$1" == "x" ]]
then
usage
exit 1
fi
GIT_REPO_REMOTE="$1"
create_working_dir
git clone "$GIT_REPO_REMOTE" "$LOCAL_REPO" > $GIT_CLONE_LOG 2>&1
RES=$?
if [[ $RES -ne 0 ]]
then
clean_working_dir
exit 2
fi
OIFS=$IFS
cd $LOCAL_REPO
BRANCHES="`git branch -r | grep -v HEAD | grep -i feature`"
IFS="
"
printf "{"
printf "\"repo\":\"$GIT_REPO_REMOTE\","
printf "\"branches\": ["
for BRANCH in $BRANCHES
do
SHORT_NAME=`echo $BRANCH | awk -F'/' '{print $2}' | sed s/' '//g`
printf "{\"branchName\":\"$SHORT_NAME\","
git checkout $SHORT_NAME > /dev/null 2>&1
RESULT="`_check_branch_against_branch "$SHORT_NAME" "origin/master"`"
printf "\"master\":$RESULT,"
RESULT="`_check_branch_against_branch "origin/develop" "$SHORT_NAME"`"
printf "\"develop\":$RESULT},"
done
printf "\b]}"
IFS=$OIFS
clean_working_dir
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment