SAS | Using Git and multi-repository environments

Inhaltsverzeichnis

Using Git Hooks

$ git config --global core.hooksPath .githooks

Anhang: .githooks

prepare-commit-msg

#!/bin/bash
#

COMMIT_MSG_FILE=$1
COMMIT_SOURCE=$2
SHA1=$3

branchPath=$(git symbolic-ref -q HEAD)
branchName=${branchPath##*/}


if [ -n "$branchName" ]; then
    echo "$branchName | $(cat $1)" > $1
fi

pre-commit

#!/bin/bash
#

_BRANCHPATH=$(git symbolic-ref -q HEAD)
_BRANCH=${_BRANCHPATH##*/}

_TIMESTAMP="$(date '

LOG() {
        if [[ "$GIT_COMMIT_DETAILED_LOGGING" == "YES" ]]; then
                echo "LOG: $*"
        fi
}

REPLACE()
{
   local _TYP;   _TYP="$1"; shift
   local _TAG;   _TAG="$1"; shift
   local _WITH; _WITH="$1"; shift
   local _FILE; _FILE="$1"; shift

   case "$_TYP" in
      SAS)       # 
                 perl -pi -e 's/(.*)
                ;;
      CUSTOMER) # /* __DEPLOY_TAG =
                perl -pi -e 's/(\/\*\s*)('"__DEPLOY_$_TAG"'\s*=\s*)(.*$)/${1}${2
                ;;
      *)        LOG "Undefined typ '$TYP' for file $_FILE"
                ;;
   esac

   rm -f "${_FILE}.bak"
}

LOG "working on branch $_BRANCH"

for _FILE in $(git diff-index --name-status --cached HEAD | grep -v ^D | cut -c3-)
do
        LOG "checking file $_FILE"

        # Only examine known text files
        if [[ "$_FILE" =~ [.](sas)$ ]]; then
                LOG "working on file $_FILE"
                REPLACE SAS TAG       "$_BRANCH"    "$_FILE"
                REPLACE SAS TIMESTAMP "$_TIMESTAMP" "$_FILE"
        fi

        if [[ "$_FILE" =~ ^MA03 ]]; then
                LOG "working on bihis-customer script  $_FILE"
                REPLACE CUSTOMER TAG       "$_BRANCH"    "$_FILE"
                REPLACE CUSTOMER TIMESTAMP "$_TIMESTAMP" "$_FILE"
        fi
done