Skip to content

Instantly share code, notes, and snippets.

@lancehudson
Last active March 1, 2022 15:05
Show Gist options
  • Save lancehudson/488121fb57ae026b78a4 to your computer and use it in GitHub Desktop.
Save lancehudson/488121fb57ae026b78a4 to your computer and use it in GitHub Desktop.
Chronos repo sync hooks

apparently the first alphabetical name is the name of the gist, otherwise this whould be readme.md

prereqs: gem install socksify

do a ./pull.sh at least once into this repo and when you clone it use the flag --recursive

because gists dont allow subdirs, hooks_setup.sh should be hooks/setup.sh go ahead and fix all of those and chmod +x both the pre-* hooks.

and run hooks/setup.sh to set the hooks up

I know I am breaking git by forcing one continous commit stream like this is CVS or something. But these are running configs on the server, maybe later I will branch them but for now, git is a versioned scp, sorry.

[submodule "chronos"]
path = chronos
url = https://github.com/mesos/chronos
#!/bin/bash
# Check if the individual developer has his own hook
CMD_NAME=$(basename $0)
if [ -f "${GIT_DIR}/hooks/personal/${CMD_NAME}" ]
then
# If so, run it. $@ passes all the command line arguments passed to this function
# If the personal hook fails, fail this one as well
if ! "${GIT_DIR}/hooks/personal/${CMD_NAME} $@"
then
echo "User hook '${CMD_NAME}' failed"
exit 1
fi
fi
exec git fetch -q
STATUS=$(git status --porcelain -b -u no)
if [[ "${STATUS}" == *"behind"* ]]; then
echo "Master is not current, run 'git pull' before commiting."
exit 1
fi
exit 0
#!/bin/bash
# Check if the individual developer has his own hook
CMD_NAME=$(basename $0)
if [ -f "${GIT_DIR}/hooks/personal/${CMD_NAME}" ]
then
# If so, run it. $@ passes all the command line arguments passed to this function
# If the personal hook fails, fail this one as well
if ! "${GIT_DIR}/hooks/personal/${CMD_NAME} $@"
then
echo "User hook '${CMD_NAME}' failed"
exit 1
fi
fi
# Check if we actually have commits to push
commits=`git log @{u}..`
if [ -z "$commits" ]; then
exit 0
fi
exec git push --dry-run --no-verify -q
REMOTE=$1
COMMIT_MSG=$(git rev-list --oneline --first-parent --max-count=1 ${REMOTE}/master..master)
if [[ "${COMMIT_MSG}" = *"[skip]"* ]]
then
echo "Skipping deploy!";
else
echo "Deploying!";
exec bash push.sh
fi
exit 0

hooks included:

pre-commit which forces you to use an up to date repo (I know this is not how git does, but it is needed for this use case). If you need to bypass this run git commit with the --no-verify option.

pre-push which pushes changes to chronos assuming you have a connection to hera. Add [skip] if you dont want to deploy. (Note, I only check the last commit being pushed.)

Personalization:

Ty https://mpdaugherty.wordpress.com/2010/04/06/how-to-include-git-hooks-in-a-repository-and-still-personalize-your-machine/

if any developer does decide to add their own hooks in /hooks/personal/, they should be sure to add a line containing /hooks/personal/*[^.sample] to the end of their /.git/info/exclude file so that git will ignore their customizations.

#!/bin/bash
ROOTDIR=$(git rev-parse --show-toplevel)
if [ -d "${ROOTDIR}/.git/hooks" ]; then
rm -r ${ROOTDIR}/.git/hooks
fi
ln -s ../hooks ${ROOTDIR}/.git/hooks
ln -s ${ROOTDIR}/.git/info/exclude ../hooks/exclude
#!/bin/bash
socksify_ruby localhost 1080 ./chronos/bin/chronos-sync.rb -u ${CHRONOS_SERVER_URL} -c -p . $1
#!/bin/bash
socksify_ruby localhost 1080 ./chronos/bin/chronos-sync.rb -u ${CHRONOS_SERVER_URL} -p . $1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment