├── AUTHORS ├── README ├── TODO └── git-bzr /AUTHORS: -------------------------------------------------------------------------------- 1 | History 2 | ------- 3 | 4 | git-bzr was originally implementedin Ruby by frimmirf@gmail.com, and 5 | improvements were added by Pieter de Bie . 6 | 7 | Bash version 8 | ------------ 9 | 10 | git-bzr was converted to bash by Matej Cepl 11 | 12 | Further improvements have been made by: 13 | 14 | Yaroslav Halchenko 15 | Jonas Bernoulli 16 | Conrad Parker 17 | Yuri Baburov 18 | Gonéri Le Bouder 19 | Gisle Aas 20 | أحمد المحمودي (Ahmed El-Mahmoudy) 21 | Gabriel Filion 22 | Giuseppe Scrivano 23 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | git-bzr: a bidirectional git - bazaar gateway 2 | ============================================= 3 | 4 | This script allows you to add bazaar repositories as git branches in your 5 | git repository. After that, you can fetch the Bazaar repo, make some 6 | changes, and push it back into Bazaar. 7 | 8 | Usage 9 | ----- 10 | 11 | An example session goes like this: 12 | 13 | $ git init 14 | $ git-bzr add upstream ../bzr-branch 15 | $ git-bzr fetch upstream 16 | $ git checkout -b local_branch upstream 17 | $ Hack hack, merge merge.... 18 | $ git-bzr push upstream 19 | 20 | bzr URLs 21 | -------- 22 | 23 | Note that a bzr URL corresponds to a single bzr branch, and is represented in 24 | git as a single branch in your repository. 25 | 26 | The URL passed to "git-bzr add" can be any valid bzr URL, such as: 27 | 28 | * A local filesystem reference 29 | git-bzr add upstream ../bzr-branch 30 | * A remote bzr repository: 31 | git-bzr add mega-nerd http://www.mega-nerd.com/Bzr/libsndfile-dev/ 32 | * A Launchpad URL: 33 | git-bzr add upstream lp:inkscape 34 | 35 | 36 | Installation 37 | ------------ 38 | 39 | You need a new Git (v 1.6.0 or higher). 40 | 41 | Furthermore, you need the Bazaar fastimport plugin. It can be found at 42 | https://launchpad.net/bzr-fastimport; to fetch it, run: 43 | 44 | $ bzr branch lp:bzr-fastimport 45 | 46 | Finally, you need to install the git-bzr script somewhere. 47 | 48 | License 49 | ------- 50 | 51 | The git-bzr script is licensed under the same license as Git. 52 | 53 | 54 | SEE ALSO 55 | ======== 56 | 57 | The following are rewrites in Python and may offer better bzr integration: 58 | 59 | * http://github.com/termie/git-bzr-ng 60 | 61 | * http://github.com/matthew-brett/git-bzr 62 | -------------------------------------------------------------------------------- /TODO: -------------------------------------------------------------------------------- 1 | 2 | Documentation 3 | ------------- 4 | 5 | Features 6 | -------- 7 | 8 | Add a way to show all bzr remote bzr branch names (similar to "git remote show"); 9 | nb. "git branch" will show bzr remotes as normal git branches, but it would 10 | be useful to have a git-bzr option to show only bzr remotes. 11 | 12 | Add a way to delete remote bzr branches (similar to "git remote rm") 13 | Add a way to rename remote bzr branches (similar to "git remote rename") 14 | nb. Using "git branch rm" and "git branch mv" does not update the git-bzr info 15 | in .git/config, so it would be useful to have a git-bzr specific command that 16 | keeps that info in sync. 17 | Add a clone command to make it easier to import a bzr as a git repository from 18 | scratch. Simplified workflow for this: mkdir, git init, 19 | git bzr add $branch $location, git bzr fetch $branch, git merge $branch. 20 | $branch should be chosen automatically. 21 | 22 | -------------------------------------------------------------------------------- /git-bzr: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | #emacs: -*- mode: shell-script; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: nil -*- 3 | #ex: set sts=4 ts=4 sw=4 et: 4 | # 5 | # git-bzr 6 | # 7 | # Bidirectional operation with Bazaar repositories. Add remote branches, pull 8 | # from them and push to them using this script. 9 | 10 | gitbzr_version='1.2' 11 | 12 | function gitbzr_help_header() { 13 | echo >&2 "git-bzr - Bidirectional operation between Bazaar and git" 14 | } 15 | 16 | function gitbzr_git_directory() { 17 | gitdir=$(git rev-parse --git-dir) 18 | [ -e "$gitdir" ] || exit 1 19 | if [ $(uname -s) != "Darwin" ]; then 20 | gitdir=$(readlink -f $gitdir) 21 | fi 22 | 23 | echo $gitdir 24 | } 25 | 26 | function gitbzr_help_all() { 27 | gitbzr_help_header 28 | echo >&2 "Usage: git bzr [arguments]" 29 | echo >&2 30 | echo >&2 "Commands:" 31 | echo >&2 32 | echo >&2 " add Add a bzr branch as a remote" 33 | echo >&2 " fetch Fetch from bzr into a named branch" 34 | echo >&2 " push Push to the tracked bzr branch" 35 | echo >&2 " show Print location of a tracked bzr branch" 36 | echo >&2 " help Display help for a specific command" 37 | echo >&2 38 | echo >&2 "Options:" 39 | echo >&2 40 | echo >&2 " --version Show git-bzr version" 41 | echo >&2 " --help Show this message" 42 | echo >&2 43 | echo >&2 "Arguments are detailed in each command's help message. For more" 44 | echo >&2 "information, use 'git bzr help '" 45 | echo >&2 46 | } 47 | 48 | function gitbzr_print_version() { 49 | cat << EOT 50 | git-bzr (bash version) $gitbzr_version 51 | Copyright (C) of respective authors (see AUTHORS). 52 | This is free software; see the source for copying conditions. There is NO 53 | warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 54 | 55 | EOT 56 | } 57 | 58 | function perror() { 59 | echo "git-bzr: $@" >&2 60 | } 61 | 62 | function gitbzr_add_help() { 63 | gitbzr_help_header 64 | echo >&2 "Add a remote bzr branch to your git repository" 65 | echo >&2 66 | echo >&2 "Usage: git-bzr add /path/to/bzr/branch" 67 | echo >&2 68 | exit 1 69 | } 70 | 71 | function gitbzr_add() { 72 | if [ $# -lt 2 ] ; then 73 | gitbzr_add_help 74 | fi 75 | name="$1" 76 | location="$2" 77 | if [[ -z "$@" ]] ; then 78 | gitbzr_add_help 79 | fi 80 | if [ -n "$(git remote show | grep -q \"$name\")" ] ; then 81 | perror "There is already a remote with that name" 82 | exit 1 83 | fi 84 | if [ -n "$(git config git-bzr.${name}.url)" ] ; then 85 | perror "There is already a bazaar branch with that name" 86 | exit 1 87 | fi 88 | if ! bzr info -q ${location} > /dev/null 2>&1 ; then 89 | perror "Remote is not a bazaar repository" 90 | exit 1 91 | fi 92 | 93 | git config "git-bzr.${name}.location" "$location" 94 | echo -e "Bazaar branch $name added.\nYou can fetch it with 'git bzr fetch $name'." 95 | } 96 | 97 | function get_location() { 98 | if [ $# -lt 1 ] ; then 99 | echo "At least the name of the remote is needed for get_location" 100 | exit 1 101 | fi 102 | remote=$1 103 | shift 104 | args=$@ 105 | l="$(git config git-bzr.${remote}.location)" 106 | if [ -z "$l" ] ; then 107 | perror "Cannot find bazaar remote with name '${remote}'." 108 | exit 1 109 | fi 110 | return="$l" 111 | } 112 | 113 | function gitbzr_show_help() { 114 | gitbzr_help_header 115 | echo >&2 "Print location of a tracked bzr branch" 116 | echo >&2 117 | echo >&2 "Usage: git bzr show " 118 | echo >&2 119 | exit 1 120 | } 121 | 122 | function gitbzr_show() { 123 | if [ $# -lt 1 ] ; then 124 | gitbzr_show_help 125 | fi 126 | remote=$1 127 | get_location "$remote" 128 | echo $return 129 | } 130 | 131 | function gitbzr_fetch_help() { 132 | gitbzr_help_header 133 | echo >&2 "Fetch from bzr into a named branch. The branch must have been" 134 | echo >&2 "added with 'git bzr add' first." 135 | echo >&2 136 | echo >&2 "Usage: git bzr fetch " 137 | echo >&2 138 | exit 1 139 | } 140 | 141 | function gitbzr_fetch_branch() { 142 | location=$1 143 | remote=$2 144 | if [ -n "$3" ] ; then 145 | branch=$3 146 | bzr_source="$location/$branch" 147 | else 148 | branch="master" 149 | bzr_source="$location" 150 | fi 151 | git_branch="$remote/$branch" 152 | 153 | gitdir=$(gitbzr_git_directory) 154 | git_map="$gitdir/bzr-git/${remote}/${branch}-git-map" 155 | bzr_map="$gitdir/bzr-git/${remote}/${branch}-bzr-map" 156 | 157 | if [ ! -f "$git_map" -a ! -f "$bzr_map" ] ; then 158 | echo "There doesn't seem to be an existing refmap. " 159 | echo "Doing an initial import of $branch_source into $git_branch" 160 | mkdir -p "$(dirname $git_map)" 161 | bzr fast-export --export-marks=${bzr_map} \ 162 | --git-branch=${git_branch} ${bzr_source} \ 163 | | sed -e 's@commit refs/heads@commit refs/remotes@g' \ 164 | -e '/^author <> [[:digit:]]\+ [+-][[:digit:]]\{4\}$/d' \ 165 | | git fast-import --export-marks=${git_map} 166 | elif [ -f "$git_map" -a -f "$bzr_map" ] ; then 167 | echo "Updating branch ${git_branch}" 168 | old_rev="$(git rev-parse ${git_branch})" 169 | bzr fast-export --import-marks=${bzr_map} \ 170 | --export-marks=${bzr_map} --git-branch=${git_branch} ${bzr_source} \ 171 | | sed -e 's@commit refs/heads@commit refs/remotes@g' \ 172 | -e '/^author <> [[:digit:]]\+ [+-][[:digit:]]\{4\}$/d' \ 173 | | git fast-import --quiet --export-marks=${git_map} \ 174 | --import-marks=${git_map} 175 | new_rev="$(git rev-parse ${git_branch})" 176 | echo "Changes since last update:" 177 | git shortlog ${old_rev}..${new_rev} 178 | else 179 | perror "One of the mapfiles is missing! Something went wrong!" 180 | exit 1 181 | fi 182 | } 183 | 184 | function gitbzr_fetch() { 185 | if [ $# -lt 1 ] ; then 186 | gitbzr_fetch_help 187 | fi 188 | remote=$1 189 | shift 190 | args=$@ 191 | if [ -z "${remote}${args}" ] ; then 192 | gitbzr_fetch_help 193 | fi 194 | get_location "$remote" 195 | location=$return 196 | 197 | branches=$(bzr branches $location) 198 | if [ -z "$branches" ] ; then 199 | # no branch -> branch, not shared repo 200 | gitbzr_fetch_branch $location $remote 201 | else 202 | for branch in $branches ; do 203 | gitbzr_fetch_branch $location $remote $branch 204 | done 205 | fi 206 | } 207 | 208 | function gitbzr_push_help() { 209 | gitbzr_help_header 210 | echo >&2 "Push to a tracked bzr branch" 211 | echo >&2 212 | echo >&2 "Usage: git bzr push " 213 | echo >&2 214 | exit 1 215 | } 216 | 217 | function gitbzr_push() { 218 | if [ $# -lt 1 ] ; then 219 | gitbzr_push_help 220 | fi 221 | gitdir=$(gitbzr_git_directory) 222 | remote=$1 223 | shift 224 | args=$@ 225 | 226 | if [ -z "${remote}${args}" ] ; then 227 | gitbzr_push_help 228 | fi 229 | get_location "$remote" 230 | location=$return 231 | 232 | if [ -n "$(git rev-list --left-right HEAD...$remote | sed -n '/^>/ p')" ] ; then 233 | perror "HEAD is not a strict child of {remote}, cannot push. Merge first" 234 | exit 235 | fi 236 | 237 | if [ -z "$(git rev-list --left-right HEAD...$remote | sed -n '/^&1 285 | exit 0 286 | elif [ "x$1" = "x--manpage" ]; then 287 | # Generate man page from help. Requires help2man, not intended for end users. 288 | help2man -N $0 289 | exit 0 290 | fi 291 | 292 | gitbzr_help $1 293 | fi 294 | 295 | cmd=$1 296 | shift 297 | args="$@" 298 | 299 | if [ "x$cmd" != "xhelp" ]; then 300 | git rev-parse 1>/dev/null 2>&1 301 | if [ $? -ne 0 ] ; then 302 | perror "Must be inside a git repository to work" 303 | exit 1 304 | fi 305 | # Move to the top-most folder in the git working folder 306 | # (so that file paths work) 307 | up=$(git rev-parse --show-cdup) 308 | if [ "x$up" != "x" ] ; then 309 | cd $up 310 | fi 311 | fi 312 | 313 | case $cmd in 314 | help ) 315 | gitbzr_help $1 316 | ;; 317 | add ) 318 | gitbzr_add $args 319 | ;; 320 | fetch ) 321 | gitbzr_fetch $args 322 | ;; 323 | push ) 324 | gitbzr_push $args 325 | ;; 326 | show ) 327 | gitbzr_show $args 328 | ;; 329 | * ) 330 | gitbzr_help 331 | ;; 332 | esac 333 | } 334 | 335 | return="" 336 | 337 | gitbzr_run $@ 338 | --------------------------------------------------------------------------------