Permalink
Browse files

'upstream' -- script to maintain local copies of external repos

instructions and notes in the source
  • Loading branch information...
sitaramc committed Jun 5, 2012
1 parent f59ad8c commit 8b78dee18ca851bc7a84a664040422626063fcb1
Showing with 43 additions and 0 deletions.
  1. +43 −0 src/triggers/upstream
View
@@ -0,0 +1,43 @@
+#!/bin/bash
+
+# Demo script: manage local, gitolite-controlled, copies of upstream repos.
+
+# Every time a client fetches such a repo, an upstream fetch happens, then the
+# client fetch is completed. Optionally, you can be "nice" and impose a
+# minimum delay between 2 fetches.
+
+# See bottom of file for instructions and notes.
+
+# ----------------------------------------------------------------------
+
+repo=$2 # see doc/triggers.mkd for arguments
+
+url=$(gitolite git-config $repo gitolite-options.upstream.url)
+[ -z "$url" ] && exit 0 # exit if no url was specified
+
+cd $GL_REPO_BASE/$repo.git
+
+nice=$(gitolite git-config $repo gitolite-options.upstream.nice)
+[ -n "$nice" ] && {
+ # exit if lastfetch was less than $nice minutes ago
+ find .gl.upstream.lastfetch -mmin -$nice | grep . >/dev/null && exit 0
+ touch .gl.upstream.lastfetch
+}
+
+git fetch -q "$url" '+refs/*:refs/*'
+
+# ----------------------------------------------------------------------
+
+# To install, add 'upstream' to the PRE_GIT trigger list in the rc file.
+#
+# Example setup to manage your own copy of the git repository:
+# repo git
+# R = @all
+# RW+ my-company/ = @developers
+# option upstream.url = git://git.kernel.org/pub/scm/git/git.git
+# option upstream.nice = 120 # (optional) minimum 2 hours between fetches
+
+# Notes:
+# 1. we don't use a remote; due to refspec being +refs/*:refs/* we don't need one
+# 2. please restrict local pushes, if any, to a namespace that the upstream won't use
+# 3. if the upstream URL changes, change the conf file accordingly and push the admin repo

0 comments on commit 8b78dee

Please sign in to comment.