1

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?

e271p314
  • 3,841
  • 7
  • 36
  • 61

1 Answers1

2

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.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • This looks like a very interesting direction, I will certainly give it a try and accept your answer if it will work for me. – e271p314 Oct 15 '13 at 11:38
  • I have a problem which prevent me from using post-receive hook. My local repositories are encrypted and only the users which send requests to the system know the passwords. I'll appreciate if you'll take a look at [this question](http://stackoverflow.com/questions/19390283/can-i-issue-git-rev-parse-on-remote-repository-without-a-local-copy). You opinion counts! – e271p314 Oct 15 '13 at 20:25
  • @e271p314 any chance that the hook 1/ update a non-bare repo *within* the encrypted disk 2/ *rsync* any changes to a non-repo copy of that working tree, located *outside* the encrypted disk? Meaning a copy from inside to outside, as opposed to a hook going outside the encrypted volume, unable to read inside. – VonC Oct 15 '13 at 20:40
  • Not sure I understood your full intention but I'm not allowed to copy any information from the encrypted volume to a non encrypted volume. The users are the one who supply the credentials to their git repo and the password to the encrypted volume. All I do is when they ask me to build the binary is to compile it from various sources. I must be sure I that I have all the latest changes but running pull on few git repo when only one was update is a waste of time (usually the repo of the user). I have the git repo credentials, can I query the remote repo directly without using my local copy? – e271p314 Oct 15 '13 at 21:06
  • I guess you answered the question in the title. But the answer I was looking for is the command `git ls-remote`. For further details see [this question](http://stackoverflow.com/questions/19390283/can-i-issue-git-rev-parse-on-remote-repository-without-a-local-copy) – e271p314 Oct 16 '13 at 10:17
  • 1
    @e271p314 Sure: I have included a reference (with relevant extracts) to this other question in my answer, for more visibility. – VonC Oct 16 '13 at 10:22