Git mirror as "gateway repository"

Viewed 170

I need to work with a git repository, where the upstream master repo is located in some closed network to which I don't have direct access. I can access it only via a gateway server. Let's denote the involved machines:

  • A: My local computer on which I'm coding
  • B: Gateway server
  • C: Upstream master server

My idea was to create a git mirror on B:

B$ git clone --mirror address-of-C:my-repo.git

On A I would clone normally from B then:

A$ git clone address-of-B:my-repo.git

But how to keep B and C in sync? First, in push-direction I imagined it easy by putting a post-receive hook on B, which pushes the received changes further to C:

#!/bin/bash
git push origin
if [[ $? -ne 0 ]]; then 
  echo 'Mirroring failed!'
  exit 1
fi

However, this fails horribly if the push in the hook fails due to upstream conflicts, leaving me in a strange state in which I should perform a merge in the bare repository in B. I tried to mitigate this my doing a git fetch in the pre-receive hook, but this fails with a message error: ref updates forbidden inside quarantine environment.

Second, in the pull-direction I have no idea how to do this at all, because there is no such thing as a "pre-pull" hook. My only idea is to periodically pull by a cron-job, but this sounds not really right to me.

Any ideas how to solve such a case? I'm not a git expert, but I assumed with the myriad of options and features of git there should be some way to do this.

1 Answers

This doesn't technically answer the question of setting up a synchronized mirror, but you may be able to tunnel to C via B, using SSH tunneling or similar.

Related