#!/bin/bash # # Usage: update-mirror # # Derived from girocco's taskd/clone.sh script. See # http://repo.or.cz/w/girocco.git set -e cfg_gitweburl=http://$(hostname)/gitweb cfg_reporoot=/var/lib/git/mirrors url=$1 projdir=$2 proj="${projdir%.git}" echo "[$proj] update mirror" echo "[$proj] $url -> $projdir" if [ ! -d "$cfg_reporoot/$projdir" ]; then echo "[$proj] $projdir is a new project" mkdir -p "$cfg_reporoot/$projdir" touch "$cfg_reporoot/$projdir/.new_clone" fi touch "$cfg_reporoot/$projdir/.clone_in_progress" cd "$cfg_reporoot/$projdir" trap "echo \"[$proj] clone failed\"; touch .clone_failed" EXIT mail="sysadmin" # Initial mirror echo "[$proj] mirroring..." case "$url" in svn://* | svn+http://* | svn+https://*) # we just remove svn+ here, so svn+http://... becomes http://... svnurl="${url#svn+}" if [ -f "$cfg_reporoot/$projdir/.new_clone" ]; then echo "[$proj] initial git-svn setup" git --git-dir . --bare init git --git-dir . svn init -s --prefix=svn-origin/ "$svnurl" # have git-svn store branches under svn-origin/heads/* not svn-origin/* # FIXME: may need to do similar when new branches are added git --git-dir . config svn-remote.svn.branches \ "$(git config --get svn-remote.svn.branches | \ sed 's|:refs/remotes/svn-origin/\*$|:refs/remotes/svn-origin/heads/*|')" git --git-dir . svn fetch # Neat Trick suggested by Miklos Vajna git --git-dir . config remote.origin.url . git --git-dir . config remote.origin.fetch \ '+refs/remotes/svn-origin/heads/*:refs/heads/*' git --git-dir . config --add remote.origin.fetch \ '+refs/remotes/svn-origin/trunk:refs/heads/master' git --git-dir . config --add remote.origin.fetch \ '+refs/remotes/svn-origin/tags/*:refs/tags/*' rm -f "$cfg_reporoot/$projdir/.new_clone" fi echo "[$proj] fetching new commits from upstream" git --git-dir . svn fetch git --git-dir . fetch ;; darcs://*) echo "[$proj] darcs mirrors not yet supported" exit 1 httpurl="${url/darcs:\/\//http://}" /usr/bin/darcs-fast-export --export-marks=$(pwd)/dfe-marks "$httpurl" | \ git fast-import --export-marks=$(pwd)/gfi-marks # This is here because by default only the exit code of # git fast-import is checked [ ${PIPESTATUS[0]} = 0 -a ${PIPESTATUS[1]} = 0 ] ;; bzr://*) echo "[$proj] bazaar mirrors not yet supported" exit 1 # we just remove bzr:// here, a typical bzr url is just # "lp:foo" bzrurl="${url#bzr://}" bzr fast-export --export-marks=$(pwd)/bfe-marks "$bzrurl" | \ git fast-import --export-marks=$(pwd)/gfi-marks [ ${PIPESTATUS[0]} = 0 -a ${PIPESTATUS[1]} = 0 ] ;; *) if [ -f "$cfg_reporoot/$projdir/.new_clone" ]; then echo "[$proj] initial git setup" git --git-dir . --bare init git --git-dir . remote rm origin >/dev/null 2>&1 || : git --git-dir . remote add --mirror origin "$url" fi echo "[$proj] fetching new commits from upstream" git --git-dir . remote update git --git-dir . remote prune origin ;; esac # The rest git update-server-info trap "" EXIT rm .clone_in_progress echo "[$proj] clone updated. See $cfg_gitweburl/?p=mirrors/$projdir;a=summary"