partial-copy: manually spot-tested (i.e., no test in suite). PW.

This commit is contained in:
Sitaram Chamarty 2012-03-23 12:36:05 +05:30
parent 0748b1225b
commit 329d757167
2 changed files with 67 additions and 0 deletions

32
src/VREF/partial-copy Executable file
View file

@ -0,0 +1,32 @@
#!/bin/sh
# push updated branches back to the "main" repo.
# This must be run as the *last* VREF, though it doesn't matter what
# permission you give to it
die() { echo "$@" >&2; exit 1; }
repo=$GL_REPO
user=$GL_USER
ref=$1 # we're running like an update hook
old=$2
new=$3
# never send any STDOUT back, to avoid looking like a ref. If we fail, git
# will catch it by our exit code
exec >&2
main=`git config --file $GL_REPO_BASE/$repo.git/config --get gitolite.partialCopyOf`;
[ -z "$main" ] && exit 0
rand=$RANDOM
export GL_BYPASS_UPDATE_HOOK=1
git push -f $GL_REPO_BASE/$main.git $new:refs/heads/br-$rand || die "FATAL: failed to send $new"
cd $GL_REPO_BASE/$main.git
git update-ref -d refs/heads/br-$rand
git update-ref $ref $new $old || die "FATAL: update-ref for $ref failed"
exit 0

35
src/commands/partial-copy Executable file
View file

@ -0,0 +1,35 @@
#!/bin/sh
# this is a wee bit expensive in terms of forks etc., compared to doing it in
# perl, but I wanted to show how *easy* it actually is now. And really,
# you'll only notice if you access this repo like a hundred times a minute or
# something so don't sweat it.
# given a repo and a user, check if option('partialCopyOf') is set, and if so,
# fetch all allowed branches from there.
die() { echo "$@" >&2; exit 1; }
# make sure we're being called from the pre_git trigger
[ "$1" = "PRE_GIT" ] || die I must be called from PRE_GIT, not "$1"
shift
repo=$1
user=$2
main=`git config --file $GL_REPO_BASE/$repo.git/config --get gitolite.partialCopyOf`;
[ -z "$main" ] && exit 0
# "we", "our repo" => the partial copy
# "main", "pco" => the one which we are a "partial copy of"
cd $GL_REPO_BASE/$main.git
for ref in `git for-each-ref refs/heads '--format=%(refname)'`
do
gitolite access -q $repo $user R $ref &&
cd $GL_REPO_BASE/$repo.git
git fetch -f $GL_REPO_BASE/$main.git $ref:$ref
done
exit 0