JoseM
JoseM

Reputation: 4302

Push to gerrit using SourceTree

I can't figure out how to make SourceTree push to Gerrit.

I saw this link but I still don't understand how it can be done: https://answers.atlassian.com/questions/29361/configuring-sourcetree-push-for-gerrit

Apparently according to the release notes for 1.3.3 there is a way to do it but I can't figure it out: http://www.sourcetreeapp.com/update/ReleaseNotes.html#version-1.3.3

Is there a step by step guide somewhere as to how to do it?

Right now I run this command on the terminal to push

git push origin HEAD:refs/for/master

Upvotes: 14

Views: 20353

Answers (2)

Jonas Bang Christensen
Jonas Bang Christensen

Reputation: 1051

If you have a setup with Git Flow (http://nvie.com/posts/a-successful-git-branching-model/), or similar, you often want to push your local branch to a different remote branch. In such a case the generic push rule (mentioned by mozart27) will not work as it always pushes your local branch to the corresponding remote branch.

Example: I have a local branch "feature123" which is ready for review (i.e. Gerrit). Our integration branch is "origin/develop". If I use the generic push rule then "feature123" will be pushed for review on "origin/feature123", but what I really want is to push it for review on "origin/develop".

Solution: In SourceTree you can create a Custom Action:

Menu caption: Push for review
Script to run: cmd
Parameters: /c git push origin $SHA:refs/for/develop

Remember to add Git to your path to enable cmd to use it.

Then, instead of clicking "Push", you right-click your commit, and select "Custom Actions -> Push for review".

Ofcourse these 2 solutions can coexist, having the generic push rule ensuring that you always send for review when pushing to a remote branch, and the custom action for when you want to send a feature branch for review on the integration branch.

Upvotes: 1

mozart27
mozart27

Reputation: 336

I believe the answer provided by atlassian says to change the name of the remote branch when you see the Push dialog.

  1. Open the push dialog
  2. Click on the remote branch name under the "Remote Branch" column (mine is presently 'master')
  3. Type in the new remo branch name - which would be 'refs/for/master' for me
  4. Click OK.

This appears to have properly pushed the commits into Gerrit for me. The problem I have now is that the 'refs/for/master' value doesn't persist. Now to figure that out. I will update this post once I've figured that out. Hope this helps even tho it's late to the game.

Update: it turns out that you need to add a push entry under remote origin in the .git/config. You should do this via the git config command (tho i did edit the file manually i'm sure that's bad practice). the push line i wrote is:

push = refs/heads/*:refs/for/*

for clarity here is my remote origin entry in .git/config:

[remote "origin"]
    url = ssh://gerrit-test.example.com:29418/mystuff.git
    fetch = +refs/heads/*:refs/remotes/origin/*
    push = refs/heads/*:refs/for/*

In SourceTree you can now push and it will push to gerrit instead of the final repo. ( you can now also just do git push without specifying anything else and it will push to gerrit ). Note that after a push, SourceTree will still show a number on the Push button that says you still have stuff to push. This is because it is still fetching from the master repo and the changes you've pushed into gerrit have not yet been merged into the master repo. Once your changes have been merged into the master repo the number on the Push button will disappear.

Upvotes: 31

Related Questions