当“ git push”到git Gogs存储库时,如何从服务器调用脚本?

时间:2019-04-12 16:20:29

标签: git github ssh githooks

当从本地存储库向git gogs存储库调用git push时,我需要在服务器上运行脚本

#!/bin/sh
git pull origin test

source env/bin/activate
pip install --upgrade pip
pip install -r requirements.txt

python manage.py migrate
python manage.py collectstatic --noinput

sudo systemctl restart gunicorn.service
sudo systemctl restart celery-worker.service
sudo systemctl restart celery-beat.service

在Internet上减去了-您需要使用git Hooks。弄清楚如何编辑钩子。

问题-如何从git Hooks通过SSH通过服务器运行文件?

ssh user@my.server

这不起作用!

1 个答案:

答案 0 :(得分:0)

考虑到server-side hook已经在(Git Gogs)服务器上执行,您不需要ssh。

确保将脚本作为可执行的接收后文件放在Gogs repositories bare repos之一中。

然后在该挂钩中执行:

#!/bin/bash
echo "pull from non-bare repo"
unset GIT_DIR
cd /path/to/checkedout/repo
git --work-tree=. --git-dir=.git pull --no-rebase origin test
... rest of your script

确保/ path / to / checkedout / repo是您的Gogs存储库之一的克隆。