Skip to content

Commit

Permalink
Merge branch 'master' of http://github.com/kfish/git-bzr
Browse files Browse the repository at this point in the history
Conflicts:
	TODO
	git-bzr
  • Loading branch information
goneri committed Mar 12, 2010
2 parents 1a3cf90 + 7cf4d24 commit 1f75fef
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 61 deletions.
4 changes: 4 additions & 0 deletions TODO
Expand Up @@ -16,4 +16,8 @@ Add a way to rename remote bzr branches (similar to "git remote rename")
nb. Using "git branch rm" and "git branch mv" does not update the git-bzr info nb. Using "git branch rm" and "git branch mv" does not update the git-bzr info
in .git/config, so it would be useful to have a git-bzr specific command that in .git/config, so it would be useful to have a git-bzr specific command that
keeps that info in sync. keeps that info in sync.
Add a clone command to make it easier to import a bzr as a git repository from
scratch. Simplified workflow for this: mkdir, git init,
git bzr add $branch $location, git bzr fetch $branch, git merge $branch.
$branch should be chosen automatically.


141 changes: 80 additions & 61 deletions git-bzr
@@ -1,41 +1,53 @@
#!/bin/bash #!/bin/bash
# #
# git-bzr # git-bzr
#
# Bidirectional operation with Bazaar repositories. Add remote branches, pull
# from them and push to them using this script.


gitdir=$(git rev-parse --git-dir) function gitbzr_help_header() {
[ -e "$gitdir" ] || exit 1 echo >&2 "git-bzr - Bidirectional operation between Bazaar and git"
}


if [ $(uname -s) != "Darwin" ]; then function gitbzr_git_directory() {
gitdir=$(readlink -f $gitdir) gitdir=$(git rev-parse --git-dir)
fi [ -e "$gitdir" ] || exit 1
if [ $(uname -s) != "Darwin" ]; then
gitdir=$(readlink -f $gitdir)
fi

echo $gitdir
}


function gitbzr_help_all() { function gitbzr_help_all() {
echo >&2 "git-bzr, Bidirectional operation between a Bzr repository and git" gitbzr_help_header
echo >&2 echo >&2 "Usage: git bzr <command> [arguments]"
echo >&2 "Usage: git-bzr <command> ..." echo >&2
echo >&2 echo >&2 "Commands:"
echo >&2 "Commands:" echo >&2
echo >&2 echo >&2 " add Add a bzr branch as a remote"
echo >&2 " add Add a bzr branch as a remote" echo >&2 " fetch Fetch from bzr into a named branch"
echo >&2 " fetch Fetch from bzr into a named branch" echo >&2 " push Push to the tracked bzr branch"
echo >&2 " push Push to the tracked bzr branch" echo >&2 " show Print location of a tracked bzr branch"
echo >&2 " show Print location of a tracked bzr branch" echo >&2 " help Display help for a specific command"
echo >&2 echo >&2
echo >&2 " help Display help for a specific command" echo >&2 "Arguments are detailed in each command's help message. For more"
echo >&2 echo >&2 "information, use 'git bzr help <command>'"
exit 1 echo >&2
exit 1
} }


function perror() { function perror() {
echo "git-bzr: $@" >&2 echo "git-bzr: $@" >&2
} }


function gitbzr_add_help() { function gitbzr_add_help() {
echo >&2 "git-bzr, Bidirectional operation between a Bzr repository and git" gitbzr_help_header
echo >&2 echo >&2 "Add a remote bzr branch to your git repository"
echo >&2 "Usage: git-bzr add <remote> /path/to/bzr/branch" echo >&2
echo >&2 echo >&2 "Usage: git-bzr add <remote> /path/to/bzr/branch"
exit 1 echo >&2
exit 1
} }


function gitbzr_add() { function gitbzr_add() {
Expand Down Expand Up @@ -81,11 +93,12 @@ function get_location() {
} }


function gitbzr_show_help() { function gitbzr_show_help() {
echo >&2 "git-bzr show, Print location of a tracked bzr branch" gitbzr_help_header
echo >&2 echo >&2 "Print location of a tracked bzr branch"
echo >&2 "Usage: git-bzr show <remote>" echo >&2
echo >&2 echo >&2 "Usage: git bzr show <remote>"
exit 1 echo >&2
exit 1
} }


function gitbzr_show() { function gitbzr_show() {
Expand All @@ -98,17 +111,20 @@ function gitbzr_show() {
} }


function gitbzr_fetch_help() { function gitbzr_fetch_help() {
echo >&2 "git-bzr fetch, Fetch from bzr into a named branch" gitbzr_help_header
echo >&2 echo >&2 "Fetch from bzr into a named branch. The branch must have been"
echo >&2 "Usage: git-bzr fetch <remote>" echo >&2 "added with 'git bzr add' first."
echo >&2 echo >&2
exit 1 echo >&2 "Usage: git bzr fetch <remote>"
echo >&2
exit 1
} }


function gitbzr_fetch() { function gitbzr_fetch() {
if [ $# -lt 1 ] ; then if [ $# -lt 1 ] ; then
gitbzr_fetch_help gitbzr_fetch_help
fi fi
gitdir=$(gitbzr_git_directory)
remote=$1 remote=$1
shift shift
args=$@ args=$@
Expand All @@ -126,17 +142,16 @@ function gitbzr_fetch() {
echo "Doing an initial import" echo "Doing an initial import"
mkdir -p "$(dirname $git_map)" mkdir -p "$(dirname $git_map)"
bzr fast-export --export-marks=${bzr_map} \ bzr fast-export --export-marks=${bzr_map} \
--git-branch=bzr/${remote} ${location} \ --git-branch=${remote} ${location} \
| sed 's/reset\ refs\/tags\/version\ /reset\ refs\/tags\//' \
| git fast-import --export-marks=${git_map} | git fast-import --export-marks=${git_map}
elif [ -f "$git_map" -a -f "$bzr_map" ] ; then elif [ -f "$git_map" -a -f "$bzr_map" ] ; then
echo "Updating remote ${remote}" echo "Updating remote ${remote}"
old_rev="$(git rev-parse bzr/${remote})" old_rev="$(git rev-parse ${remote})"
bzr fast-export --import-marks=${bzr_map} \ bzr fast-export --import-marks=${bzr_map} \
--export-marks=${bzr_map} --git-branch=bzr/${remote} ${location} \ --export-marks=${bzr_map} --git-branch=${remote} ${location} \
| git fast-import --quiet --export-marks=${git_map} \ | git fast-import --quiet --export-marks=${git_map} \
--import-marks=${git_map} --import-marks=${git_map}
new_rev="$(git rev-parse bzr/${remote})" new_rev="$(git rev-parse ${remote})"
echo "Changes since last update:" echo "Changes since last update:"
git shortlog ${old_rev}..${new_rev} git shortlog ${old_rev}..${new_rev}
else else
Expand All @@ -146,17 +161,19 @@ function gitbzr_fetch() {
} }


function gitbzr_push_help() { function gitbzr_push_help() {
echo >&2 "git-bzr push, Push to the tracked bzr branch" gitbzr_help_header
echo >&2 echo >&2 "Push to a tracked bzr branch"
echo >&2 "Usage: git-bzr push <remote>" echo >&2
echo >&2 echo >&2 "Usage: git bzr push <remote>"
exit 1 echo >&2
exit 1
} }


function gitbzr_push() { function gitbzr_push() {
if [ $# -lt 1 ] ; then if [ $# -lt 1 ] ; then
gitbzr_push_help gitbzr_push_help
fi fi
gitdir=$(gitbzr_git_directory)
remote=$1 remote=$1
shift shift
args=$@ args=$@
Expand All @@ -167,12 +184,12 @@ function gitbzr_push() {
get_location "$remote" get_location "$remote"
location=$return location=$return


if [ -n "$(git rev-list --left-right HEAD...bzr/$remote | sed -n '/^>/ p')" ] ; then if [ -n "$(git rev-list --left-right HEAD...$remote | sed -n '/^>/ p')" ] ; then
perror "HEAD is not a strict child of {remote}, cannot push. Merge first" perror "HEAD is not a strict child of {remote}, cannot push. Merge first"
exit exit
fi fi


if [ -z "$(git rev-list --left-right HEAD...bzr/$remote | sed -n '/^</ p')" ] ; then if [ -z "$(git rev-list --left-right HEAD...$remote | sed -n '/^</ p')" ] ; then
perror "Nothing to push. Commit something first" perror "Nothing to push. Commit something first"
exit exit
fi fi
Expand Down Expand Up @@ -213,22 +230,30 @@ function gitbzr_help() {
} }


function gitbzr_run() { function gitbzr_run() {
if [ $# -lt 2 ] ; then
gitbzr_help $1
fi

cmd=$1 cmd=$1
shift shift
args="$@" args="$@"


if [ -n "$(git rev-parse)" ] ; then if [ "x$cmd" != "xhelp" ]; then
perror "Must be inside a git repository to work" git rev-parse 1>/dev/null 2>&1
exit 1 if [ $? -ne 0 ] ; then
fi perror "Must be inside a git repository to work"
up=$(git rev-parse --show-cdup) exit 1
if [ "x$up" == "x" ] ; then fi
up="." up=$(git rev-parse --show-cdup)
if [ "x$up" == "x" ] ; then
up="."
fi
cd $up
fi fi
cd $up
case $cmd in case $cmd in
help ) help )
gitbzr_help $args gitbzr_help $1
;; ;;
add ) add )
gitbzr_add $args gitbzr_add $args
Expand All @@ -248,12 +273,6 @@ function gitbzr_run() {
esac esac
} }


if [ $# -lt 1 ] ; then
gitbzr_help
fi

command=$1

return="" return=""


gitbzr_run $@ gitbzr_run $@

0 comments on commit 1f75fef

Please sign in to comment.