从Netbeans推到Grit的Git [英] Git pushing from Netbeans to Gerrit

查看:130
本文介绍了从Netbeans推到Grit的Git的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Netbeans 7.4(在linux上)推荐提交评论给Gerrit时遇到问题。我的git配置:

 
[core]
repositoryformatversion = 0
filemode = true
logallrefupdates = true
bare = false
[remoteorigin]
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

当我尝试启动Git - > Remote - > Push to Upstream时,我收到没有为本地主机指定的跟踪远程分支错误。当我使用Git - > Remote - > Push ...时,我的提交总是直接添加到主分支。 Netbeans日志:

 
== [IDE] == 2014-02-24 16:37:53推送 - gitTestWeb3
git分支
git remote -v
设置remote:origin
git push ssh://xxx@git.yyyy.com:9418 / xxx / gitTestWeb3 refs / heads / master:refs / heads / master
远程仓库更新
分支更新:master
旧标识:38806fc76a933f4538a5f0b9fc500bd69309faba
新标识:38806fc76a933f4538a5f0b9fc500bd69309faba
结果:UP_TO_DATE

本地仓库更新
分行更新:产地/主
旧编号:9d048427bb50d7de642083a903a18a11568eadec
新编号:38806fc76a933f4538a5f0b9fc500bd69309faba
结果:FAST_FORWARD

== [IDE] == 2014 -02-24 16:37:54推 - gitTestWeb3完成。

是否有强制Neteans git插件来遵守git配置的方法?或者我应该配置其他的东西?



顺便说一句,它也接缝,git钩子没有被解雇;我已经安装了Gerrit的commit-msg,但NB提交后没有修改消息;从命令行它完美的工作。

BTW2完全相同的git配置与eclipse(事件Juno)完美配合。获取主要是完成,而所有的推动来到refs / for / master进行审查。

解决方案

从IDE开始工作(在这里使用来自IDE的稍微松散的定义),我不得不自己推出一些。希望NetBeans团队或有时间掌握的社区中的某位英雄能够根据回购类型和安装的钩子从IDE中的提交对话框中获得此工作。只要你的终端在NetBeans中工作(我的情况是Windows上的Cygwin),你可以很容易地获得你需要的变更标识符的消息,并且也可以让Gerrit发布工作。



我首先将commit-msg形式的钩子复制到了我的路径(我的用户的bin)中的一个目录中,并在最后一行添加了 $ @ 脚本,以便可以从命令行调用脚本的功能。然后我添加了一个用于调用它的别名,以及用于从本地回购库执行Gerrit发布的另一个别名。我还在NetBeans提交对话框的加载模板弹出式对话框中创建了一个简单的提交消息模板,如下所示:

  Change- Id:I 

在提交消息中预先填充它是很好的,因为它提醒我(我们刚开始使用Gerrit)代码审查需要完成,我需要填写其余的变更ID。这是我的.bashrc别名:

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

获取消息的其余更改ID部分并在其上添加任何其他行以进行更改并提交,我准备从我的分支根目录的命令行中调用别名发布到Gerrit。这里是:
$ b $ pre $ alias gerritPublish ='_ gerritPublish'
_gerritPublish()
{
localBranch =`git rev-parse --abbrev-ref HEAD`
git push -u --progressoriginHEAD:refs / publish / dev / $ localBranch
}
$ p
$ b

修改最后提交仍然可以在IDE的提交对话框中正常工作,并填写正确的消息并更改ID,所以很好。我喜欢使用IDE的提交对话框,而不是单独使用命令行,因为它的内置并行处理功能非常棒。尽管如此,所有这些都没有我想要的那么干净,但它现在运行良好,而且我不必启动任何其他工具或离开NetBeans,所以我希望它有帮助。


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.

解决方案

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.

这篇关于从Netbeans推到Grit的Git的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆