diff --git a/src-rev-commit.sh b/src-rev-commit.sh new file mode 100755 index 0000000..9c862e3 --- /dev/null +++ b/src-rev-commit.sh @@ -0,0 +1,130 @@ +#!/bin/bash + +SCRIPT_PARAMS="$*" +SCRIPT_PATHNAME=$(realpath ${0}) +SCRIPT_NAME=$(basename ${SCRIPT_PATHNAME}) +SCRIPT_PATH=$(dirname ${SCRIPT_PATHNAME}) + +export LOGFILE=/dev/null +export BRANCH_NAME=develop +export IS_DUMMY=false +export IS_VERBOSE=false + +#********************************************************************************************** +# local helper functions +#********************************************************************************************** +#---------------------------------------------------------------------------------------------- +function printUsage() +{ + echo -e "\nUsage: ${SCRIPT_NAME} [OPTIONS]\n" + echo -e "" + echo -e " OPTIONS:" + echo -e " -b|--branch=BRANCH_NAME commit to branch BRANCH_NAME (default = ${BRANCH_NAME})" + echo -e " -d|--dummy-commit display found SRVREVs" + echo -e " -l|--log=LOGFILE write some output to LOGFILE (default = $LOGFILE)" + echo -e " -h|--help Show this help" + echo -e " -v|--verbose Set script to verbose" +} +#---------------------------------------------------------------------------------------------- +function logMessage() +{ + local msg="${1}" + echo "${msg}" >> $LOGFILE +} +#---------------------------------------------------------------------------------------------- +function printMessage() +{ + local msg="${1}" + logMessage "${msg}" + if [[ "${IS_VERBOSE}" == "false" ]]; then + return + fi + echo "${msg}" +} +#---------------------------------------------------------------------------------------------- +function updateLayerToHead() { + local layer="${1}" + local branch="${2}" + + logMessage "--> checking out branch ${BRNCH_NAME}" + git checkout ${BRANCH_NAME} >> $LOGFILE 2>&1 + logMessage "--> pull changes ${BRANCH_NAME}" + git pull >> $LOGFILE 2>&1 +} + +#********************************************************************************************** +# main +#********************************************************************************************** +O=$(getopt -o hb:l:vd --long help,branch:,log:,verbose,dummy-commit -- "$@") || exit 1 +if [ $? != 0 ]; then + echo "ERROR: Could not parse command line options" + exit 1 +fi + +eval set -- "$O" +while true; do + case "${1}" in + -b|--branch) + export BRANCH_NAME="${2}" + shift 2 + ;; + -v|--verbose) + export IS_VERBOSE=true + shift + ;; + -d|--dummy-commit) + export IS_DUMMY=true + shift + ;; + -l|--log) + export LOGFILE="${2}" + export LOGFILE=$(realpath "${LOGFILE}") + shift 2 + ;; + -h|--help) + export IS_VERBOSE=false + printUsage + exit 0 + ;; + --) + shift + break + ;; + *) + printUsage; exit 0 ;; + esac +done + +echo "${SCRIPT_NAME} called with ${SCRIPT_PARAMS}" > $LOGFILE + + +for nmLayer in $(git status | grep "meta-netmodule" | cut -d':' -f2 | sed -e 's/^[ ]*//' | cut -d' ' -f1); do + cd $nmLayer + nbrChanges=$(git status | grep "modified:" | wc -l) + printMessage "${nbrChanges} changes in layer ${nmLayer}" + if [[ "${nbrChanges}" != "0" ]]; then + logMessage "--> stash the changes first to checkout branch head..." + git stash save >> $LOGFILE 2>&1 + updateLayerToHead "${nmLayer}" "${BRANCH_NAME}" + logMessage "--> get changes back from stash..." + git stash pop >> $LOGFILE 2>&1 + logMessage "--> adding tracked and changed files" + git add -u >> $LOGFILE 2>&1 + printMessage "--> committing and pushing..." + commitMsg="${nmLayer}: updated source revisions" + if [[ "${IS_DUMMY}" == "true" ]]; then + printMessage " dummy commit: msg='${commitMsg}', content:" + git status | grep "modified" >> $LOGFILE 2>&1 + # revert changes to simulate a commit :-P + git reset HEAD * > /dev/null + git checkout * > /dev/null + else + git commit -m "${commitMsg}" >> $LOGFILE 2>&1 + git push >> $LOGFILE 2>&1 + fi + printMessage "----------" + fi + cd .. +done + +exit 0 \ No newline at end of file