forked from 0k/0k-charms
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
129 lines
4.4 KiB
129 lines
4.4 KiB
#!/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
|