Auto-deploy files other than config and hooks.
[git-central.git] / server / post-receive-gitconfig
1 #!/bin/sh
2 #
3 # Copyright (c) 2008 Stephen Haberman
4 #
5 # Auto-deploys the contents of the gitconfig branch to $GIT_DIR.
6 #
7 # The config file is handled specially--instead of the $GIT_DIR's config file
8 # being copied over entirely, the gitconfig:config is evaluated line by line
9 # with calls to `git config`. This means you can have settings in
10 # $GIT_DIR/config that are not in the gitconfig:config and they will not be
11 # overwritten.  Deleting $GIT_DIR/config entries has to be manually.
12 #
13 # Hooks are copied over entirely, but old ones are not deleted. Deleting
14 # existing hooks has to be done manually.
15 #
16
17 while read oldrev newrev refname ; do
18         if [ "$refname" == "refs/heads/gitconfig" ] ; then
19                 config_hash=$(git ls-tree $newrev | grep config | grep -oP '\w{40}')
20                 if [[ "$config_hash" != "" ]] ; then
21                         git cat-file blob "$config_hash" | while read line ; do
22                                 key="${line%=*}"
23                                 value="${line#*=}"
24                                 git config "${key}" "${value}"
25                         done
26                 fi
27
28                 hooks_hash=$(git ls-tree $newrev | grep hooks | grep -oP '\w{40}')
29                 if [[ "$hooks_hash" != "" ]] ; then
30                         git ls-tree "$hooks_hash" | while read mode type file_hash file_name ; do
31                                 echo "Installing $file_name"
32                                 git cat-file blob "$file_hash" > "hooks/$file_name"
33                         done
34                 fi
35
36                 git ls-tree $newrev | grep -v hooks | grep -v config | grep blob | while read mode type file_hash file_name ; do
37                         echo "Installing $file_name"
38                         git cat-file blob "$file_hash" > "$file_name"
39                 done
40         fi
41 done
42