Skip to content

Instantly share code, notes, and snippets.

@mrkcor
Created August 14, 2013 05:19
Show Gist options
  • Save mrkcor/6228218 to your computer and use it in GitHub Desktop.
Save mrkcor/6228218 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
# Using this script as your post-receive hook will update mirrors using git
# push --mirror. To make this work you have to ensure that access is taken
# care of (for example by setting up .ssh/config with an SSH key for the
# user that runs the hook).
#
# To use this script populate /home/git/git-mirrors.yml with YAML like so:
# ---
# user/repo1.git:
# - otheruser@otherhost:/path/to/mirror1.git
# - otheruser@otherhost:/path/to/mirror2.git
# user/repo2.git:
# - otheruser@otherhost:/path/to/mirror3.git
require 'yaml'
begin
repo_name = Dir.pwd.split('/')[-2..-1].join('/')
mirrors = YAML.load_file('/home/git/git-mirrors.yml')
mirrors.fetch(repo_name, []).each do |mirror|
pid = spawn("git push --mirror #{mirror}")
Process.detach(pid)
end
rescue Exception => e
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment