Push all GIT branches to Gerrit

241 views
Skip to first unread message

Emmanuel Grumbach

unread,
Dec 24, 2009, 6:36:25 AM12/24/09
to repo-d...@googlegroups.com
Hi all,

recently I had to push a whole Android project to Gerrit. I downloaded it with repo but not from Gerrit and wanted to push it to Gerrit including all the branches. The main issue was that I repo would create only one GIT branch in each repository, the branch that matches the manifest.

Finally I wrote this script:

#!/bin/bash -f

username=MYNAME
gerrit_srv=MY_SERVER_NAME

#foreach remote branch, create a local branch with the same name that tracks it
createLocalBranch() {
        local BRANCHES=$*
        for B in ${BRANCHES}; do
                git branch `echo $B | cut -d"/" -f2` --track $B
        done
}

pushAllBranchesToGerrit() {
        #get the list of remote branches without the spaces at the beginning
        local BRANCHES=`git branch -r | cut -d" " -f3`

        createLocalBranch ${BRANCHES}

        # push all the changes to Gerrit server
        git push --all ssh://${username}@${gerrit_srv}:29418/${REPO_PROJECT}
}

pushAllBranchesToGerrit

________________________________________

Then from the TOP dir of Android:

repo forall -c 'FuzzyScript.sh'

I rely here on the fact that repo forall brings me to the dir of each project.

Finally I had all my branches in Gerrit.

I am sending this first to have comment if I did something wrong, or superfluous. Second to help people that might want to do something similar.

Emmanuel Grumbach
egru...@gmail.com

Emmanuel Grumbach

unread,
Dec 24, 2009, 12:35:02 PM12/24/09
to repo-d...@googlegroups.com
Of course I forgot to push tags here...
Emmanuel Grumbach
egru...@gmail.com

Shawn Pearce

unread,
Dec 24, 2009, 2:37:08 PM12/24/09
to repo-d...@googlegroups.com
Emmanuel Grumbach <egru...@gmail.com> wrote:
> recently I had to push a whole Android project to Gerrit. I downloaded it
> with repo but not from Gerrit and wanted to push it to Gerrit including all
> the branches. The main issue was that I repo would create only one GIT
> branch in each repository, the branch that matches the manifest.

Well, you could have done this a few different ways, but yes,
this isn't something done without additional script support.

One alternative, you could have used a repo mirror client:

repo init ... --mirror
repo sync
repo forall -c git push --all 'ssh://username@srv:29418/${REPO_PROJECT}'

as the local refs/heads namespace would match the upstream project.


You could also have done this without creating local tracking
branches. In a non-mirror client:

repo forall -c '
git push --all ssh://username@srv:29418/$REPO_PROJECT \
$(git for-each-ref \
--format='%(refname):%(refname)' \
refs/remotes/$REPO_REMOTE |
sed s,:refs/remotes/$REPO_REMOTE/,:refs/heads/,)
'

Message has been deleted

SenthilV

unread,
Jan 22, 2010, 5:03:48 PM1/22/10
to Repo and Gerrit Discussion
Thanks for this info, this is truly great stuff.

In FuzzyScript, I changed the first cut line:


git branch `echo $B | cut -d"/" -f2` --track $B

to this:
git branch `echo $B | sed s:origin/::` --track $B

because I had some branches with two slashes and cut didn't parse
those correctly.

-senthil

On Dec 24 2009, 11:37 am, Shawn Pearce <s...@google.com> wrote:

Reply all
Reply to author
Forward
0 new messages