forked from sysprog21/lab0-c
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement sanity check with pre-push hook
All participants were asked to fork from this repository, but some of them might create their repositories without forking, that caused problems for public reviewing. Thus, this patch introduced a simple way to validate current workspace by probing the existence of specific "magic" commit. In addition, when someone attempts to push master branch to remote, this hook would ensure that current workspace is buildable.
- Loading branch information
Showing
2 changed files
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#!/usr/bin/env bash | ||
|
||
protected_branch='master' | ||
current_branch=$(git symbolic-ref HEAD | sed -e 's,.*/\(.*\),\1,') | ||
RED='\033[0;31m' | ||
GREEN='\033[1;32m' | ||
YELLOW='\033[1;33m' | ||
NC='\033[0m' # No Color | ||
|
||
# Validate repository | ||
# commit d9805e67e74ea3a05956d92447bbe67214154c06 | ||
# Author: Jim Huang <[email protected]> | ||
# Date: Wed Jan 22 14:13:06 2020 +0000 | ||
# | ||
# Bump copyright year | ||
commit=`git rev-list -n 1 --grep '^Bump copyright' 0f146d62ecba1f0c098165273204d35cfa9d07ec...HEAD` | ||
if [ x"$commit" != x"d9805e67e74ea3a05956d92447bbe67214154c06" ] ; then | ||
echo -e "${RED}ERROR${NC}: This repository is insane." | ||
echo -e "Make sure you did fork from https://github.com/sysprog21/lab0-c recently." | ||
echo "" | ||
exit 1 | ||
fi | ||
|
||
# Show hints | ||
echo -e "${YELLOW}Hint${NC}: You might want to know why is Git is always ${GREEN}asking for my password${NC}." | ||
echo -e " https://help.github.com/en/github/using-git/why-is-git-always-asking-for-my-password" | ||
echo "" | ||
|
||
# only run this if you are pushing to master | ||
if [[ $current_branch = $protected_branch ]] ; then | ||
echo -e "${YELLOW}Running pre push to master check...${NC}" | ||
|
||
echo -e "${YELLOW}Trying to build tests project...${NC}" | ||
|
||
# build the project | ||
make | ||
|
||
# $? is a shell variable which stores the return code from what we just ran | ||
rc=$? | ||
if [[ $rc != 0 ]] ; then | ||
echo -e "${RED}Failed to build the project, please fix this and push again${NC}" | ||
echo "" | ||
exit $rc | ||
fi | ||
|
||
# Everything went OK so we can exit with a zero | ||
echo -e "${GREEN}Pre push check passed!${NC}" | ||
echo "" | ||
fi | ||
|
||
exit 0 |