From c631dc7f398318c628188bb0b5334ec1c45cffa0 Mon Sep 17 00:00:00 2001 From: Valentin Lab Date: Tue, 16 Apr 2013 16:33:17 +0200 Subject: [PATCH] new: added ``git`` charm. --- precise/git/hooks/install | 46 +++++++ precise/git/hooks/start | 3 + precise/git/hooks/stop | 3 + precise/git/metadata.yaml | 12 ++ precise/git/revision | 1 + precise/git/src/etc/cron.daily/git-bzr-syncs | 5 + precise/git/src/sbin/git-bzr-syncs | 129 +++++++++++++++++++ 7 files changed, 199 insertions(+) create mode 100755 precise/git/hooks/install create mode 100755 precise/git/hooks/start create mode 100755 precise/git/hooks/stop create mode 100644 precise/git/metadata.yaml create mode 100644 precise/git/revision create mode 100755 precise/git/src/etc/cron.daily/git-bzr-syncs create mode 100755 precise/git/src/sbin/git-bzr-syncs diff --git a/precise/git/hooks/install b/precise/git/hooks/install new file mode 100755 index 0000000..eeadf7c --- /dev/null +++ b/precise/git/hooks/install @@ -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 + diff --git a/precise/git/hooks/start b/precise/git/hooks/start new file mode 100755 index 0000000..9eb7853 --- /dev/null +++ b/precise/git/hooks/start @@ -0,0 +1,3 @@ +#!/bin/bash + +juju-log "Nothing to Start for base." diff --git a/precise/git/hooks/stop b/precise/git/hooks/stop new file mode 100755 index 0000000..170162b --- /dev/null +++ b/precise/git/hooks/stop @@ -0,0 +1,3 @@ +#!/bin/bash + +juju-log "Nothing to stop for base." diff --git a/precise/git/metadata.yaml b/precise/git/metadata.yaml new file mode 100644 index 0000000..52a21f0 --- /dev/null +++ b/precise/git/metadata.yaml @@ -0,0 +1,12 @@ +name: git +summary: "GIT server and services" +maintainer: "Valentin Lab " +inherit: base-0k +description: | + GIT repositories +config-resources: + - /etc/git-hooks.d + - /etc/git-bzr-syncs +data-resources: + - /var/git + - /srv/git-bzr-mirrors diff --git a/precise/git/revision b/precise/git/revision new file mode 100644 index 0000000..573541a --- /dev/null +++ b/precise/git/revision @@ -0,0 +1 @@ +0 diff --git a/precise/git/src/etc/cron.daily/git-bzr-syncs b/precise/git/src/etc/cron.daily/git-bzr-syncs new file mode 100755 index 0000000..40746e8 --- /dev/null +++ b/precise/git/src/etc/cron.daily/git-bzr-syncs @@ -0,0 +1,5 @@ +#!/bin/bash + +ansi_color=no git-bzr-syncs | logger -t oe-sync + + diff --git a/precise/git/src/sbin/git-bzr-syncs b/precise/git/src/sbin/git-bzr-syncs new file mode 100755 index 0000000..67f93a7 --- /dev/null +++ b/precise/git/src/sbin/git-bzr-syncs @@ -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