简体   繁体   English

通过FTP将文件添加到git存储库后,在脚本中使用inotifywait来自动执行git commit

[英]using inotifywait in a script to automate a git commit when files have been added to git repository via FTP

I've got a git workflow set up similar to this http://joemaller.com/990/a-web-focused-git-workflow/ . 我已经建立了一个类似于http://joemaller.com/990/a-web-focused-git-workflow/的git工作流程。 Essentially i have local repositories that report to a remote repository that is bare. 本质上,我有本地存储库,可以向裸露的远程存储库报告。 Then I have my deployment directory accessible via web also set up as a repository that also reports to the same bare repository. 然后,我可以通过Web访问我的部署目录,并将其设置为一个存储库,该存储库也向同一裸存储库报告。

It's set up with git hooks so that when local developer pushes changes to remote repository, hook goes into web folder and pulls from the repository so it always has the latest and greatest. 它使用git钩子进行设置,以便当本地开发人员将更改推送到远程存储库时,钩子进入Web文件夹并从存储库中提取,因此它始终具有最新和最大功能。 All works pretty good. 一切都很好。

My crux is that I'm looking to appease to the people who don't want to you GIT and just want to upload files to the web folder via FTP. 我的症结在于,我希望让那些不想让您使用GIT,而只想通过FTP将文件上传到Web文件夹的人安抚。 I've kinda got this working by setting up an inotifywait monitor on the web folder for whenever files are written, modified, moved, deleted, created, etc... my bash script for this is as follows. 我通过在Web文件夹上设置一个inotifywait监视器来进行此工作,以便在文件被写入,修改,移动,删除,创建等时使用……我的bash脚本如下。

!/bin/sh
inotifywait @*.swp -rm -e modify,move,create,delete,delete_self,unmount /var/www/html/mysite | while read
do

now=$(date +"%m_%d_%Y:%T")
echo $now >> temp.txt

cd /var/www/html/mysite || exit
git add --all
git commit -m "ftp update $now" -a
done

This too actually works, but what I'm observing is that I'm stuck in the while loop once I trigger the inotifywait by modifying a file in my web folder. 这实际上也可行,但是我观察到的是,一旦我通过修改Web文件夹中的文件触发了inotifywait,就陷入了while循环。 Anyone have any ideas on this? 有人对此有任何想法吗? Ideally would love it to do it's thing and not be stuck in the while loop continuously running unnecessary git commands. 理想情况下,它会喜欢它做它的事情,而不会被困在while循环中,连续运行不必要的git命令。

Thanks! 谢谢!

The man page for inotifywait suggests that you do a different loop style: inotifywait手册页建议您使用其他循环样式:

while inotifywait -e modify /var/log/messages; do
    …
done

have you tried that? 你有尝试过吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM