Skip to content

Instantly share code, notes, and snippets.

@friedmud
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save friedmud/9199319 to your computer and use it in GitHub Desktop.
Save friedmud/9199319 to your computer and use it in GitHub Desktop.
moose pre_test
if [[ $base_ref != "devel" ]]; then
echo "Pull requests MUST be for the devel branch!!"
exit 1
fi
# Go to where the MOOSE repo was cloned
cd $REPO_DIR
git reset HEAD --hard
# Check out the devel branch (note, we might already be there, that's ok)
git co devel
# clean it
git clean -xfdq
# Update the devel branch
git pull --rebase origin devel
# Create a branch to work with (we'll delete this later)
# We're replacing the '/'es in the repo name with dashes
# to create the branch name
branch_name=${repo//\//-}
git co -b $branch_name
# Merge the branch in the pull request into this one:
git pull $ssh_url $ref
# Check for a ticket reference
TICKET_REFERENCE=`git log devel..$branch_name | perl -ne 'print if /#\d{3,}/'`
# Check for whitespace
WHITESPACE_FILES=`find . \( -name '*.[Chi]' -or -name '*.py' \) -print0 | xargs -0 perl -nle 'if ($ARGV ne $oldargv && /\s+$/) { print "\t$ARGV"; $oldargv=$ARGV }'`
# Check for banned keywords
BANNED_KEYWORDS=`find . \( -name '*.[Chi]' -or \( -name "contrib" -or -name "libmesh" \) -prune -and -type f \) -print0 | xargs -0 perl -nle 'if ($ARGV ne $oldargv && (/std::cout|std::cerr/ || /sleep\s*\(/)) { print "\t$ARGV"; $oldargv=$ARGV }'`
# Printing decisions...
one_failed=0
if [ "x$TICKET_REFERENCE" == "x" ]; then
one_failed=1
else
one_passed=1
fi
if [ "x$WHITESPACE_FILES" != "x" ]; then
one_failed=1
else
one_passed=1
fi
if [ "x$BANNED_KEYWORDS" != "x" ]; then
one_failed=1
else
one_passed=1
fi
#Print information about the passing tests
if [ $one_passed == 1 ]; then
printf "\n\n##########################################################################\n"
if [ "x$TICKET_REFERENCE" != "x" ]; then
printf "INFO: Your patch contains a valid ticket reference.\n"
fi
if [ "x$WHITESPACE_FILES" == "x" ]; then
printf "INFO: Your patch contains no trailing whitespace.\n"
fi
if [ "x$BANNED_KEYWORDS" == "x" ]; then
printf "INFO: Your patch contains no banned keywords.\n"
fi
printf "##########################################################################\n\n"
fi
#Print information about failed tests
if [ $one_failed == 1 ]; then
printf "\n##########################################################################"
if [ "x$TICKET_REFERENCE" == "x" ]; then
printf "\nERROR: Your patch does not contain a valid ticket reference! (i.e. #1234)\n"
git log devel..$branch_name --pretty='%s'
fi
if [ "x$WHITESPACE_FILES" != "x" ]; then
printf "\nERROR: The following files contain trailing whitespace after applying your patch:\n${WHITESPACE_FILES}\n"
printf "\nRun the following command in the base of your moose directory to cleanup whitespace:\n"
printf 'find . \( -name '*.[Chi]' -or -name '*.py' -or \( -name "contrib" -or -name "libmesh" \) -prune -and -type f \) -print0 | xargs -0 perl -pli -e "s/\s+$//"\n'
fi
if [ "x$BANNED_KEYWORDS" != "x" ]; then
printf "\nERROR: The following files contain banned keywords (std::cout, std::cerr, sleep):\n${BANNED_KEYWORDS}\n"
fi
printf "##########################################################################\n\n"
fi
# Clean up in the case of bad merge
git reset HEAD --hard
# Go back to the devel branch then delete this one
git co devel
git branch -D $branch_name
# Return the return code
exit $one_failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment