Tuesday, 15 March 2011

git - githook doing actions on push based on working tree -



git - githook doing actions on push based on working tree -

i want write githook that, when remote repository receives push, reads info repositories working tree , performs actions based on info can find. if breaks during hook, force should rejected! work on non-bare repository only, of course.

i found update hook quite suitable in regards of time @ called. problem have can not checkout newest ref update hook because has not been integrated yet.

#!/bin/sh # .git/hooks/update refname="$1" if [ "$refname" == "refs/heads/master" ]; newrev="$3" git checkout "$newrev" # ... read tree , perform additional actions fi

i (strangely) error message:

remote: error: local changes next files overwritten checkout: remote: somefile

if understand documentation correctly, post-update allow me checkout, not allow me reject push. there way it?

update: tried utilize post-update , run git -c .. checkout master it, get

remote: fatal: not git repository: '.'

even if pass total path non-bare remote repository, says not git repository. why that? git prevent operating on non-bare basis within hook?

update: nevermind, found out. git utilize git_dir if set (even when it's empty). the original question still open

# procedure allow utilize git on non-bare # basis. if git_dir set, git utilize directory # instead of other (cwd or passed via git -c ...) git() { unset git_dir env git $* }

update: seems can checkout $newrev although has not been integrated already. create detached head unfortunately, gives right info working tree.

if thing interested in requirements.txt file don't need check out total working directory. can instead dump 1 file out straight hook

git cat-file -p ${newrev}:<path>/requirementstxt

git githooks

No comments:

Post a Comment