Scripts/hooks to store settings in a separate 'gitconfig' branch.
authorStephen Haberman <stephen@exigencecorp.com>
Thu, 14 Aug 2008 03:19:02 +0000 (22:19 -0500)
committerStephen Haberman <stephen@exigencecorp.com>
Thu, 14 Aug 2008 03:19:02 +0000 (22:19 -0500)
scripts/make-gitconfig-branch.sh [new file with mode: 0644]
server/update-git-config [new file with mode: 0644]
tests/t2800-server-update-git-config.sh [new file with mode: 0644]

diff --git a/scripts/make-gitconfig-branch.sh b/scripts/make-gitconfig-branch.sh
new file mode 100644 (file)
index 0000000..5556038
--- /dev/null
@@ -0,0 +1,19 @@
+#!/bin/sh
+
+# Create an empty file object
+empty_file_hash=$(git hash-object -w --stdin <<FOO
+FOO)
+
+# Make a root directory tree with the config file in it
+config_tree_hash=$(git mktree <<FOO
+100644 blob $empty_file_hash   config
+FOO)
+
+# Commit the root directory tree
+commit_hash=$(git commit-tree $config_tree_hash <<FOO
+Initial commit on config branch.
+FOO)
+
+# Push the commit out to the gitconfig branch
+git update-ref refs/heads/gitconfig "$commit_hash" 0000000000000000000000000000000000000000
+
diff --git a/server/update-git-config b/server/update-git-config
new file mode 100644 (file)
index 0000000..a5fd2e7
--- /dev/null
@@ -0,0 +1,21 @@
+#!/bin/sh
+
+refname="$1"
+oldrev="$2"
+newrev="$3"
+
+if [ "$refname" != "refs/heads/gitconfig" ] ; then
+       exit 0
+fi
+
+tree_contents=$(git ls-tree $newrev)
+if [[ "$tree_contents" =~ (.{40})[[:space:]]config ]] ; then
+       config_hash=${BASH_REMATCH[1]}
+       echo "hash=$config_hash"
+       git cat-file blob "$config_hash" | while read line ; do
+               key="${line%=*}"
+               value="${line#*=}"
+               git config "${key}" "${value}"
+       done
+fi
+
diff --git a/tests/t2800-server-update-git-config.sh b/tests/t2800-server-update-git-config.sh
new file mode 100644 (file)
index 0000000..d73df30
--- /dev/null
@@ -0,0 +1,38 @@
+#!/bin/sh
+
+test_description='server update git config'
+
+. ./test-lib.sh
+
+test_expect_success 'setup' '
+       echo "setup" >a &&
+       git add a &&
+       git commit -m "setup" &&
+       git clone ./. server &&
+       rm -fr server/.git/hooks &&
+       git remote add origin ./server &&
+       git config --add branch.master.remote origin &&
+       git config --add branch.master.merge refs/heads/master &&
+       git fetch
+'
+
+install_update_hook 'update-git-config'
+
+test_expect_success 'pushing initial value works' '
+       cd server &&
+       ! git config --list | grep foo &&
+       cd .. &&
+
+       ../../scripts/make-gitconfig-branch.sh &&
+       git checkout gitconfig &&
+       echo "foo.foo=bar" > config &&
+       git commit -a -m "Set foo.foo=bar."
+       git push origin gitconfig
+
+       cd server &&
+       git config --list | grep foo &&
+       cd ..
+'
+
+test_done
+