Friday 14 August 2015

Collabnet SVN pre-commit hooks for Folders & Files

In Collabnet Subversion, if you have to put pre-commit hooks for certain folders like build, dist, bin, obj folders etc, you can use the following script:

Include the following at the end in File : /opt/csvn/data/repositories/pre-commit.sh


# Make sure that the log message contains some text.
SVNLOOK=/opt/csvn/bin/svnlook
${SVNLOOK} log -t "$TXN" "$REPOS" | /bin/grep '[[:print:]]\{20\}' > /dev/null || NO_COMMIT_MESSAGE="stop"

if [[ -n "${NO_COMMIT_MESSAGE}" ]]

then

  MORE_THAN_ALLOWED_CHARS=1

else

  #--- Exclude a specific folder for such 

  XTEST=`echo "${REPOS}" | /bin/awk '/commonlibs/ { print 1; exit}' 2>&1`
  if [[ "${XTEST}" != "1" ]]
  then
    NO_COMMIT_MESSAGE=`${SVNLOOK} changed "$REPOS" | tr A-Z a-z | /bin/awk '/\/build\// || /\/dist\// || /\.jar/ { print "stop"; exit } ' 2>&1 `

  fi

fi


if [[ "${NO_COMMIT_MESSAGE}" == "stop" ]]
 then
  echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" 1>&2
  echo 1>&2
  if [[ ${MORE_THAN_ALLOWED_CHARS} -eq 1 ]]
  then
    echo "Please provide detailed description (min 20 char) about the changes you made in the commit message." 1>&2
  else

    echo "Please exclude folders like 'build' or 'dist' and files like '*.jar' in commit." 1>&2
  fi
  echo 1>&2
  echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" 1>&2
  exit 1
 else
  exit 0
fi

=====================================================================
If you have forgotten the admin password,

you can shut down the csvn service and then go to the file:
csvn-production-hsqldb.script

and change the line referencing admin user to :

INSERT INTO USER VALUES(1,11,'$2a$13$5OuIEVEvKLUHTc/kl5kCROMgvqrlgHsdpoZSWqnaKXR6dMfSHcloO',TRUE,'admin','sunambiar@abc.in','admin user','Super Administrator')



No comments:

Post a Comment