问题
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 (includingrefs/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
andgit 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