forked from 0k/0k-charms
Valentin Lab
12 years ago
7 changed files with 199 additions and 0 deletions
-
46precise/git/hooks/install
-
3precise/git/hooks/start
-
3precise/git/hooks/stop
-
12precise/git/metadata.yaml
-
1precise/git/revision
-
5precise/git/src/etc/cron.daily/git-bzr-syncs
-
129precise/git/src/sbin/git-bzr-syncs
@ -0,0 +1,46 @@ |
|||||
|
#!/bin/bash |
||||
|
|
||||
|
set -eux # -x for verbose logging to juju debug-log |
||||
|
|
||||
|
|
||||
|
apt-get install -y --force-yes kal-shlib |
||||
|
|
||||
|
apt-get install -y bzr |
||||
|
|
||||
|
mkdir -p /var/git |
||||
|
mkdir -p /srv/git-bzr-mirrors |
||||
|
|
||||
|
mkdir -p /opt/apps |
||||
|
|
||||
|
## install git-hooks |
||||
|
(cd /opt/apps && |
||||
|
git clone -s /var/git/0k/git-hooks.git |
||||
|
) |
||||
|
|
||||
|
( |
||||
|
cd /opt/apps && |
||||
|
bzr clone lp:bzr-fastimport && |
||||
|
mkdir /root/.bazaar/plugins -p |
||||
|
ln -sf /opt/apps/bzr-fastimport /root/.bazaar/plugins/fastimport |
||||
|
|
||||
|
) |
||||
|
|
||||
|
|
||||
|
( |
||||
|
cd /opt/apps && |
||||
|
bzr clone lp:python-fastimport && |
||||
|
cd ../python-fastimport && |
||||
|
python setup.py install |
||||
|
) |
||||
|
|
||||
|
|
||||
|
( |
||||
|
cd /opt/apps && |
||||
|
git clone https://github.com/termie/git-bzr-ng.git && |
||||
|
cd /opt/apps/git-bzr-ng && |
||||
|
ln -sf /opt/apps/git-bzr-ng/git-bzr /usr/lib/git-core/ |
||||
|
) |
||||
|
|
||||
|
cp src/sbin/git-bzr-syncs /usr/sbin/git-bzr-syncs |
||||
|
cp src/etc/cron.daily/git-bzr-syncs /etc/cron.daily/git-bzr-syncs |
||||
|
|
@ -0,0 +1,3 @@ |
|||||
|
#!/bin/bash |
||||
|
|
||||
|
juju-log "Nothing to Start for base." |
@ -0,0 +1,3 @@ |
|||||
|
#!/bin/bash |
||||
|
|
||||
|
juju-log "Nothing to stop for base." |
@ -0,0 +1,12 @@ |
|||||
|
name: git |
||||
|
summary: "GIT server and services" |
||||
|
maintainer: "Valentin Lab <valentin.lab@kalysto.org>" |
||||
|
inherit: base-0k |
||||
|
description: | |
||||
|
GIT repositories |
||||
|
config-resources: |
||||
|
- /etc/git-hooks.d |
||||
|
- /etc/git-bzr-syncs |
||||
|
data-resources: |
||||
|
- /var/git |
||||
|
- /srv/git-bzr-mirrors |
@ -0,0 +1 @@ |
|||||
|
0 |
@ -0,0 +1,5 @@ |
|||||
|
#!/bin/bash |
||||
|
|
||||
|
ansi_color=no git-bzr-syncs | logger -t oe-sync |
||||
|
|
||||
|
|
@ -0,0 +1,129 @@ |
|||||
|
#!/bin/bash |
||||
|
|
||||
|
. /etc/shlib |
||||
|
|
||||
|
include common |
||||
|
include pretty |
||||
|
|
||||
|
|
||||
|
devdir=/srv/git-bzr-mirrors |
||||
|
conf_file="/etc/git-bzr-syncs/git-bzr-syncs.conf" |
||||
|
|
||||
|
if ! [ -f "$conf_file" ]; then |
||||
|
print_error "No config file found in '$conf_file'." |
||||
|
fi |
||||
|
|
||||
|
|
||||
|
modules_branch=$(cat "$conf_file" | egrep -v ^\s*# | egrep -v ^\$) |
||||
|
|
||||
|
## get branch from bzr_branch |
||||
|
function get_bzr_remote_branch() { |
||||
|
git config -l | grep "^bzr\.bzr/.*\.upstream=$1$" | |
||||
|
sed -r "s,^bzr\.(bzr/.*)\.upstream=.*$,\1," |
||||
|
|
||||
|
} |
||||
|
|
||||
|
function get_bzr_local_branch() { |
||||
|
git config -l | grep "^bzr\..*\.bzr=$1" | |
||||
|
sed -r "s,^bzr\.(.*)\.bzr=.*$,\1,g" | |
||||
|
## This is because git-bzr-ng do not support "/" in branches names |
||||
|
grep -v "/" | |
||||
|
head -n 1 |
||||
|
} |
||||
|
|
||||
|
function get_current_branch() { |
||||
|
local branch |
||||
|
branch=$(git symbolic-ref HEAD) |
||||
|
echo "${branch#refs/heads/}" |
||||
|
} |
||||
|
|
||||
|
function git_pull_remote_bzr() { |
||||
|
Wrap git checkout "$1" && |
||||
|
Wrap git bzr sync && |
||||
|
Wrap git merge --ff-only "$2" || exit 1 |
||||
|
## remove bogus tags |
||||
|
export bogus_tags=$(git tag -l | grep ^openerp-build) |
||||
|
Wrap -d "delete $(echo "$bogus_tags" | wc -l ) bogus tags" 'echo "$bogus_tags" | xargs -n 20 git tag -d ' || exit 1 |
||||
|
} |
||||
|
|
||||
|
function get_bzr_official_branch() { |
||||
|
|
||||
|
git config -l | grep "^branch\..*\.follow-git-bzr=$1$" | |
||||
|
sed -r "s,^branch\.(.*)\.follow-git-bzr=.*$,\1,g" | |
||||
|
## This is because git-bzr-ng do not support "/" in branches names |
||||
|
head -n 1 |
||||
|
: |
||||
|
} |
||||
|
|
||||
|
function git_update_official() { |
||||
|
update_to=$(git config branch.$1.follow-git-bzr) |
||||
|
|
||||
|
## XXXvlab: this should be better but current git version is not |
||||
|
## supporting "-B" |
||||
|
#Wrap git checkout -B "$1" "$update_to" |
||||
|
|
||||
|
if git branch "$1" >/dev/null 2>&1 ; then |
||||
|
Elt "Created branch $YELLOW$1$NORMAL"; Feed |
||||
|
fi |
||||
|
Wrap git checkout "$1" && |
||||
|
Wrap git reset --hard "$update_to" || exit 1 |
||||
|
} |
||||
|
|
||||
|
if [ "$1" ]; then |
||||
|
modules_branch=$(echo "$modules_branch" | grep "^$1=") |
||||
|
fi |
||||
|
|
||||
|
for line in $modules_branch; do |
||||
|
dir=$(echo "$line" | cut -f 1 -d "=") |
||||
|
bzr_branches=$(echo "$line" | cut -f 2- -d "=" | tr "," "\n") |
||||
|
Title Repository $YELLOW$dir$NORMAL |
||||
|
for bzr_branch in $bzr_branches; do |
||||
|
if ! [ -d "$devdir/$dir" ]; then |
||||
|
echo " You must clone your git repository in $devdir/$dir." |
||||
|
echo |
||||
|
echo " git clone GIT_REPO_URL $devdir/$dir" |
||||
|
echo " OR git bzr clone GIT_REPO_URL $devdir/$dir" |
||||
|
echo |
||||
|
print_error "No repository found in $devdir/$dir." |
||||
|
fi |
||||
|
cd "$devdir/$dir" |
||||
|
git_bzr_remote_branch="$(get_bzr_remote_branch $bzr_branch)" |
||||
|
if [ -z "$git_bzr_remote_branch" ]; then |
||||
|
echo " You must do the first 'git bzr' import yourself:" |
||||
|
echo |
||||
|
echo " git bzr import lp:LP_BRANCH LOCAL_BZR_BRANCH" |
||||
|
echo |
||||
|
echo " ie: git bzr import lp:openobject-addons/7.0 openobject-addons-7.0" |
||||
|
echo |
||||
|
print_error "bzr branch $bzr_branch was not configured in $dir repository." |
||||
|
fi |
||||
|
#echo " BZR REMOTE: $git_bzr_remote_branch" |
||||
|
git_bzr_local_branch="$(get_bzr_local_branch $git_bzr_remote_branch)" |
||||
|
|
||||
|
if [ -z "$git_bzr_local_branch" ]; then |
||||
|
print_error "git bzr remote branch $git_bzr_remote_branch was not linked to a branch in $dir repository." |
||||
|
fi |
||||
|
#echo " BZR LOCAL: $git_bzr_local_branch" |
||||
|
current_branch=$(get_current_branch) |
||||
|
if [ "$(git diff)" ]; then |
||||
|
print_error "Repository $dir is not clean." |
||||
|
fi |
||||
|
git_bzr_official_branch="$(get_bzr_official_branch $git_bzr_local_branch)" |
||||
|
|
||||
|
if [ -z "$git_bzr_official_branch" ]; then |
||||
|
echo " You must link $git_bzr_local_branch branch to the branch managed by 'git bzr'." |
||||
|
echo |
||||
|
echo " git config branch.$git_bzr_local_branch.follow-git-bzr LOCAL_BZR_BRANCH" |
||||
|
echo |
||||
|
print_error "git bzr local branch $git_bzr_local_branch was not linked to an official branch in $dir repository." |
||||
|
fi |
||||
|
Section "sync branch $YELLOW$git_bzr_official_branch$NORMAL" |
||||
|
Elt bzr branch: $YELLOW$bzr_branch$NORMAL ; Feed |
||||
|
Elt git intermediary branch: $YELLOW$git_bzr_local_branch$NORMAL ; Feed |
||||
|
|
||||
|
git_pull_remote_bzr "$git_bzr_local_branch" "$git_bzr_remote_branch" |
||||
|
git_update_official "$git_bzr_official_branch" |
||||
|
Wrap git push origin "$git_bzr_official_branch" || exit 1 |
||||
|
Wrap git push --tags || exit 1 |
||||
|
done |
||||
|
done |
Write
Preview
Loading…
Cancel
Save
Reference in new issue