Gitolite gl-post-init钩子自动化

回答如下

我目前正在build立一个本地git /开发服务器,并遇到与gitolite post-hook的障碍。

概述我目前正在做的事情。

我已经设置了一个本地服务器,其中包含一个4TB RAID10被用作git存储库,该机器也被用作本地开发机器,并简化了维护,我试图自动创buildApache虚拟主机的过程,当一个新的存储库是通过gitolite“git-post-init”创build的。

我希望通过克隆存储库的软件分支(请参阅下面的代码)来完成此操作,在apache vhostconfiguration中添加,然后以符号方式将其链接到apache扫描的目录。

这个过程似乎是正确的,因为我能克隆存储库添加一些初始文件,并创buildconfiguration文件,但是当我试图在存储库中做任何git相关的命令,我提出了以下错误

fatal: Not a git repository: '.' 

如果在钩子运行后进入新克隆的仓库,我可以调用仓库的状态。

 git status 

哪些工作…它似乎只是试图做任何这个钩子内没有。

下面是正在使用的钩子代码,删除额外的configuration来缩短它。

 #!/bin/sh # This will create an apache virtualhost file and store it in the # repositories conf/reponame.conf directory and then symlink it to # /home/git/apache/reponame.conf # # A new entry will then be created in the hosts file. echo "Creating a new X Studios project" echo "Git Project config v0.1 author Nickolas Whiting: Oct 20, 2011" REPO=$HOME/repos REPO_PATH=$HOME/repos/$GL_REPO cd $REPO echo "Cloning repo into $REPO_PATH" git clone $GL_REPO_BASE_ABS/$GL_REPO cd $REPO/$GL_REPO echo "Working in $PWD" echo "Adding .gitignore file" touch .gitignore echo "removed for space" >> .gitignore git add -u echo "Commiting changes to repository" git commit -m "Adding ignore file" git push echo "Adding branches" git branch --track management origin/management git branch --track design origin/design git branch --track software origin/software echo "Commiting new branches" git add . git commit -m "Inital Project Setup. Make sure you use the correct branch for what you are doing!" git push echo "Checking out the software branch" git checkout software echo "Creating Apache Virtualhost configuration" echo "Removed for space" >> $REPO_PATH/conf/$GL_REPO.conf echo "Creating symbolic link" ln -s $REPO_PATH/$GL_REPO.conf $HOME/apache/$GL_REPO.conf echo "Commiting changes to the repository" echo "DONE" 

我是新的编写bash脚本,所以如果有什么错误或可以做得更好请让我知道,

谢谢您的帮助!

回答

如果其他人有这个问题

显然,在gl钩子里面运行时, GIT_DIRvariables被设置为'。' (这是显而易见的)将其设置到存储库.git目录解决了这个问题

 GIT_DIR=$PWD/.git 

希望这节省了我浪费在这个小时的人!

在git钩子里运行时,GIT_DIRvariables被设置为'。' (这是显而易见的)将其设置到存储库.git目录解决了这个问题

 GIT_DIR=$PWD/.git