How to call a script from the server, when 'git push' to the git Gogs repository?

你离开我真会死。 提交于 2019-12-08 05:06:05

问题


I need to run the script on my server, when calling git push from the local repository to the git gogs repository

#!/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

Subtracted on the Internet - that you need to use git Hooks. Figured out how to edit hooks.

Question - how can I run a file from a server via SSH from git Hooks ???

ssh user@my.server

This does not work!


回答1:


You should not need ssh, considering the server-side hook will already execute on the (Git Gogs) server.

Make sure to put your script as an executable post-receive file, in one of your Gogs repositories bare repos.

And in that hook, do:

#!/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

Make sure that /path/to/checkedout/repo is a clone of one of your Gogs repo.



来源:https://stackoverflow.com/questions/55655874/how-to-call-a-script-from-the-server-when-git-push-to-the-git-gogs-repository

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!