Skip to content

Instantly share code, notes, and snippets.

@evilchili
Created May 19, 2011 20:55
Show Gist options
  • Save evilchili/981724 to your computer and use it in GitHub Desktop.
Save evilchili/981724 to your computer and use it in GitHub Desktop.
a generic method for storing repo configuration data in git
#!/bin/bash
#
# parse configuration options from a file in the current repository.
# Designed to be invoked from git hook scripts.
#
# Sample usage: toggle automatic branch building, per-branch
#
# config file looks like:
# BranchName=option1[,option2...]
#
# be sure $newrev and $target_branch are defined, then:
config_filename='repo.cfg'
get_config_options() {
cfg_hash=$(git ls-tree $newrev | grep "$config_filename" | cut -d' ' -f 3 | cut -f 1 )
if [[ "$cfg_hash" != "" ]] ; then
opts=$( git cat-file blob "$cfg_hash" | egrep -i "^\s*${target_branch}=" | cut -d= -f 2 )
autobuild=$( echo "$opts" | grep '\<autobuild\>' )
fi
}
# in your post-receive hook...
get_config_options
if [[ $autobuild ]]; then
# trigger a build...
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment