How to make my local git copy always at its latest version automatically?

自闭症网瘾萝莉.ら 提交于 2019-12-08 08:32:07

问题


My system has few git repositories with some c++ code in them. Users which send a request to my system are getting a binary executable compiled from all the git repositories together. A basic feature of this system is to send binary built from the latest version of the source. In order to do so, each time the system gets a request it runs git pull --all, this command takes a lot of time. I want to avoid running the pull command when a request arrives and instead to make the system run the pull command automatically when the a new version is committed. How to do it automatically?

The only way I can think of is somehow to query the git server periodically every second or so and run the pull command every time there is a new commit in the remote repository but I think that polling is the last solution I'm looking for. Even so, how to implement this naive polling scheme and what alternatives do I got?


回答1:


You could put a post-receive hook on the bare repos of your git server, in order for that hook to go to a non-bare repo, and pull.
It would keep that way a working tree always up-to-date, commits after commits.

You can see an example in this question.

#!/bin/sh

unset $(git rev-parse --local-env-vars)
cd /path/to/non-bare.repo
git pull

As illustrated in the follow-up question "Can I issue git rev-parse on remote repository without a local copy?", torek mentions:

You can use git ls-remote to get the head SHA-1s from the remote (including refs/heads/master).
All that will tell you is "same" or "different", assuming you have the head SHA-1s locally.
If they are different, you can't tell precisely why (though you can get probably-enough if you walk the local revs).

Comparing the output of git ls-remote and git rev-parse master will tell me if my local repo is updated or not.

That can be a way to know when to trigger a git pull.



来源:https://stackoverflow.com/questions/19374975/how-to-make-my-local-git-copy-always-at-its-latest-version-automatically

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