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

  1. #!/bin/bash
  2. . /etc/shlib
  3. include common
  4. include pretty
  5. devdir=/srv/git-bzr-mirrors
  6. conf_file="/etc/git-bzr-syncs/git-bzr-syncs.conf"
  7. if ! [ -f "$conf_file" ]; then
  8. print_error "No config file found in '$conf_file'."
  9. fi
  10. modules_branch=$(cat "$conf_file" | egrep -v ^\s*# | egrep -v ^\$)
  11. ## get branch from bzr_branch
  12. function get_bzr_remote_branch() {
  13. git config -l | grep "^bzr\.bzr/.*\.upstream=$1$" |
  14. sed -r "s,^bzr\.(bzr/.*)\.upstream=.*$,\1,"
  15. }
  16. function get_bzr_local_branch() {
  17. git config -l | grep "^bzr\..*\.bzr=$1" |
  18. sed -r "s,^bzr\.(.*)\.bzr=.*$,\1,g" |
  19. ## This is because git-bzr-ng do not support "/" in branches names
  20. grep -v "/" |
  21. head -n 1
  22. }
  23. function get_current_branch() {
  24. local branch
  25. branch=$(git symbolic-ref HEAD)
  26. echo "${branch#refs/heads/}"
  27. }
  28. function git_pull_remote_bzr() {
  29. Wrap git checkout "$1" &&
  30. Wrap git bzr sync &&
  31. Wrap git merge --ff-only "$2" || exit 1
  32. ## remove bogus tags
  33. export bogus_tags=$(git tag -l | grep ^openerp-build)
  34. Wrap -d "delete $(echo "$bogus_tags" | wc -l ) bogus tags" 'echo "$bogus_tags" | xargs -n 20 git tag -d ' || exit 1
  35. }
  36. function get_bzr_official_branch() {
  37. git config -l | grep "^branch\..*\.follow-git-bzr=$1$" |
  38. sed -r "s,^branch\.(.*)\.follow-git-bzr=.*$,\1,g" |
  39. ## This is because git-bzr-ng do not support "/" in branches names
  40. head -n 1
  41. :
  42. }
  43. function git_update_official() {
  44. update_to=$(git config branch.$1.follow-git-bzr)
  45. ## XXXvlab: this should be better but current git version is not
  46. ## supporting "-B"
  47. #Wrap git checkout -B "$1" "$update_to"
  48. if git branch "$1" >/dev/null 2>&1 ; then
  49. Elt "Created branch $YELLOW$1$NORMAL"; Feed
  50. fi
  51. Wrap git checkout "$1" &&
  52. Wrap git reset --hard "$update_to" || exit 1
  53. }
  54. if [ "$1" ]; then
  55. modules_branch=$(echo "$modules_branch" | grep "^$1=")
  56. fi
  57. for line in $modules_branch; do
  58. dir=$(echo "$line" | cut -f 1 -d "=")
  59. bzr_branches=$(echo "$line" | cut -f 2- -d "=" | tr "," "\n")
  60. Title Repository $YELLOW$dir$NORMAL
  61. for bzr_branch in $bzr_branches; do
  62. if ! [ -d "$devdir/$dir" ]; then
  63. echo " You must clone your git repository in $devdir/$dir."
  64. echo
  65. echo " git clone GIT_REPO_URL $devdir/$dir"
  66. echo " OR git bzr clone GIT_REPO_URL $devdir/$dir"
  67. echo
  68. print_error "No repository found in $devdir/$dir."
  69. fi
  70. cd "$devdir/$dir"
  71. git_bzr_remote_branch="$(get_bzr_remote_branch $bzr_branch)"
  72. if [ -z "$git_bzr_remote_branch" ]; then
  73. echo " You must do the first 'git bzr' import yourself:"
  74. echo
  75. echo " git bzr import lp:LP_BRANCH LOCAL_BZR_BRANCH"
  76. echo
  77. echo " ie: git bzr import lp:openobject-addons/7.0 openobject-addons-7.0"
  78. echo
  79. print_error "bzr branch $bzr_branch was not configured in $dir repository."
  80. fi
  81. #echo " BZR REMOTE: $git_bzr_remote_branch"
  82. git_bzr_local_branch="$(get_bzr_local_branch $git_bzr_remote_branch)"
  83. if [ -z "$git_bzr_local_branch" ]; then
  84. print_error "git bzr remote branch $git_bzr_remote_branch was not linked to a branch in $dir repository."
  85. fi
  86. #echo " BZR LOCAL: $git_bzr_local_branch"
  87. current_branch=$(get_current_branch)
  88. if [ "$(git diff)" ]; then
  89. print_error "Repository $dir is not clean."
  90. fi
  91. git_bzr_official_branch="$(get_bzr_official_branch $git_bzr_local_branch)"
  92. if [ -z "$git_bzr_official_branch" ]; then
  93. echo " You must link $git_bzr_local_branch branch to the branch managed by 'git bzr'."
  94. echo
  95. echo " git config branch.$git_bzr_local_branch.follow-git-bzr LOCAL_BZR_BRANCH"
  96. echo
  97. print_error "git bzr local branch $git_bzr_local_branch was not linked to an official branch in $dir repository."
  98. fi
  99. Section "sync branch $YELLOW$git_bzr_official_branch$NORMAL"
  100. Elt bzr branch: $YELLOW$bzr_branch$NORMAL ; Feed
  101. Elt git intermediary branch: $YELLOW$git_bzr_local_branch$NORMAL ; Feed
  102. git_pull_remote_bzr "$git_bzr_local_branch" "$git_bzr_remote_branch"
  103. git_update_official "$git_bzr_official_branch"
  104. Wrap git push origin "$git_bzr_official_branch" || exit 1
  105. Wrap git push --tags || exit 1
  106. done
  107. done