Git pushing from Netbeans to Gerrit

不打扰是莪最后的温柔 提交于 2019-12-23 11:59:39

问题


I have a problem while pushing commits for review to Gerrit from Netbeans 7.4 (on linux). My git config:

[core]
        repositoryformatversion = 0
        filemode = true
        logallrefupdates = true
        bare = false
[remote "origin"]
        url = ssh://xxx@git.yyyy.com:9418/xxx/gitTestWeb3
        fetch = +refs/heads/master:refs/remotes/origin/master
        push = HEAD:refs/for/master
[user]
        name = Mxxx Cxxx
        email = xxxx@yyyy.com
[branch "master"]
        remote = origin
        merge = refs/for/master
[push]
        default = upstream

When I try to start "Git -> Remote -> Push to Upstream" I receive "No tracked remote branch specified for local master" error. When I use "Git -> Remote -> Push..." my commit is always added to the master branch directly. Netbeans log:

==[IDE]== 2014-02-24 16:37:53 Pushing - gitTestWeb3
git branch
git remote -v
setting up remote: origin
git push ssh://xxx@git.yyyy.com:9418/xxx/gitTestWeb3 refs/heads/master:refs/heads/master
Remote Repository Updates
Branch Update : master
Old Id        : 38806fc76a933f4538a5f0b9fc500bd69309faba
New Id        : 38806fc76a933f4538a5f0b9fc500bd69309faba
Result        : UP_TO_DATE

Local Repository Updates
Branch Update : origin/master
Old Id        : 9d048427bb50d7de642083a903a18a11568eadec
New Id        : 38806fc76a933f4538a5f0b9fc500bd69309faba
Result        : FAST_FORWARD

==[IDE]== 2014-02-24 16:37:54 Pushing - gitTestWeb3 finished.

Is it any way to enforce Neteans git plugin to honor git configuration? Or should I configure something else?

BTW it also seams that git hooks are not fired; I have a Gerrit's commit-msg installed, but a message is not modified after NB commit; from the command line it works perfectly.

BTW2 exactly the same git configuration works perfectly with eclipse (event Juno). Fetches are done from master while all pushes come to refs/for/master to be reviewed.


回答1:


In an effort to get this working from the IDE (using a somewhat loose definition of "from the IDE" here), I've had to roll my own a bit. Hopefully the NetBeans team or some hero of the community who has time on their hands will get this working from the commit dialog within the IDE simply based on the repo type and the installed hooks. As long as you have the terminal working in NetBeans (Cygwin on Windows in my case) you can pretty easily get the hook message Change Id you need, and also get the Gerrit publishing working too.

I first copied the commit-msg form the hook to a directory in my path (my user's bin), and added $@ on the last line of the script so that the script's functions could be called from the command line. Then I added an alias for calling it, along with another alias for performing the Gerrit publish from my local repo. I also created a simple commit message template in the NetBeans commit dialog's "Load Template" popup dialog that looks like this:

Change-Id: I

Having this get pre-populated in the commit message is nice as it reminds me (we just started using Gerrit) that code review needs to be done and I'll need to fill in the rest of the change ID. Here's my .bashrc alias for doing that:

alias getChangeId="commit-msg _gen_ChangeId 2>/dev/null"

After getting the rest of the change ID portion of the message and adding whatever other lines above it for the change and commiting, I'm ready to call the alias for publishing to Gerrit from the command line at the root of my branch. Here's that:

alias gerritPublish='_gerritPublish'
_gerritPublish ()
{
    localBranch=`git rev-parse --abbrev-ref HEAD`
    git push -u --progress "origin" HEAD:refs/publish/dev/$localBranch
}

The Amend Last Commit still works fine from the IDE's commit dialog, and fills in the correct message and change ID, so that's nice to have. I like to use the IDE's commit dialog instead of solely the command line because of it's great built in side by side diffing. Still, all of this is not as clean as I'd like, but it's working well for now, and I don't have to fire up any other tools or leave NetBeans, so I hope it helps.



来源:https://stackoverflow.com/questions/21992512/git-pushing-from-netbeans-to-gerrit

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!