我想知道如何使用jgit连接到github使用指定的ssh密钥文件(即不在〜/ .ssh /中).
不幸的是,我不确定如何JschConfigSessionFactory正确使用.我尝试创建一个类似于本文中的设置:使用JGit键来安全地访问Git存储库
我使用git调用git.push().setRemote(remotePath).call();但是,我收到此错误(日志中省略了特定的存储库):
org.eclipse.jgit.api.errors.TransportException: https://github.com/user/repo: not authorized
at org.eclipse.jgit.api.PushCommand.call(PushCommand.java:160)
at gitio.GitInterface.pushToRemote(GitInterface.java:145)
at engine.GitInterfaceTester.main(GitInterfaceTester.java:25)
Caused by: org.eclipse.jgit.errors.TransportException: https://github.com/user/repo: not authorized
at org.eclipse.jgit.transport.TransportHttp.connect(TransportHttp.java:479)
at org.eclipse.jgit.transport.TransportHttp.openPush(TransportHttp.java:396)
at org.eclipse.jgit.transport.PushProcess.execute(PushProcess.java:154)
at org.eclipse.jgit.transport.Transport.push(Transport.java:1173)
at org.eclipse.jgit.api.PushCommand.call(PushCommand.java:156)
... 2 more
Run Code Online (Sandbox Code Playgroud)
我注意到JschConfigSessionFactory实际上没有实际调用自定义覆盖方法.这几乎肯定是问题的原因......但不知道为什么不调用它们; 我将自定义传递JschConfigSessionFactory给SshSessionFactory使用SshSessionFactory.setInstance(sessionFactory);
有人知道我做错了什么吗?
我想使用 JGit 在存储库中获取最后一个提交元数据(按日期计算的最年轻的元数据)。
我知道我可以使用
try (RevWalk walk = new RevWalk(repository)) {
RevCommit commit = walk.parseCommit(repository.resolve(commitHash));
}
Run Code Online (Sandbox Code Playgroud)
但是如何获得最新的提交哈希?
有没有其他方法可以RevCommit直接在存储库中获得最年轻的日期?
我使用Eclipse(Helios)与PDT和EGit.我有一个没有版本控制的项目,所以我通过执行以下操作为它创建了一个git存储库:
Team -> Share Project
Run Code Online (Sandbox Code Playgroud)
当我尝试将项目的文件添加到存储库时:
Team -> Add
Run Code Online (Sandbox Code Playgroud)
我得到一个例外:
Failed to add resource to index
Failed to add resource to index
Exception caught during execution of add command
Run Code Online (Sandbox Code Playgroud)
当我在命令行上手动添加文件时,一切正常.
有任何想法吗?
编辑:
eclipse给出的错误是:
Caused by: org.eclipse.jgit.errors.ObjectWritingException: Unable to create new object: Z:\eage_layout\.git\objects\60\f30dd232bd6ddaeb198fb11400c2613a072189
at org.eclipse.jgit.storage.file.ObjectDirectoryInserter.insert(ObjectDirectoryInserter.java:100) at org.eclipse.jgit.api.AddCommand.call(AddCommand.java:177)
Run Code Online (Sandbox Code Playgroud)
我正在运行的代码位于CentOs上运行的虚拟机上.我正在使用Windows机器并使用samba共享来访问虚拟机上的代码.我已将.git目录上的文件系统权限设置为777,但它仍然无效.
我知道我可以通过使用isFocusControl()它来查看特定小部件是否在SWT中具有控制权.但是,当我的预期窗口小部件没有焦点时,我如何确定是什么(换句话说,什么把焦点带走了)?
我能够使用遍历侦听器来处理键盘事件,但是使用鼠标点击来改变焦点似乎会使我的应用程序变得神秘.我似乎无法弄清楚如何找到从前一项获得焦点的项目.
FocusLost如果通过鼠标事件更改焦点,我也会在侦听器内可靠地将焦点设置到另一个小部件时遇到问题.
有什么建议?
如果问题不在这里,我会将其删除.
有人知道Android是否已停止支持Eclipse插件?现在,当你从google搜索"Android SDK"进入他们的网站时,你可以下载Android Studio,我找不到Eclipse插件的位置......我记得他们说他们不会停止支持它,但是好吧,谷歌毕竟...所以有人知道吗?
我正在尝试切换按钮的背景drawable,以便当用户单击按钮时,其背景会发生变化,当用户再次单击该按钮时,其背景将返回默认值.这是我的代码:
public void Favorites(View V) {
Button star = (Button) findViewById(R.id.buttonStar);
if(star.getBackground().equals(R.drawable.btn_star_off)) {
star.setBackgroundResource(R.drawable.btn_star_on);
} else {
star.setBackgroundResource(R.drawable.btn_star_off);
}
}
Run Code Online (Sandbox Code Playgroud)
我很确定这不是你如何使用drawables与if语句.有人可以建议一种方法吗?
我不太明白这两种方法的区别.在什么情况会forceFocus()比setFocus()什么更好?
我在 scala 中使用 JGit 访问远程 Git 存储库,并且需要使用 SSH 进行身份验证。JGit 使用 JSch 提供安全访问。
我遵循了本教程:http://www.codeaffine.com/2014/12/09/jgit-authentication/
但是,我总是出现com.jcraft.jsch.JSchException:身份验证失败
我的方法是:
def sshCloneRemoteRepository() = {
// 1 / Override SSH configuration with JschConfigSessionFactory
val sshSessionFactory: SshSessionFactory = new JschConfigSessionFactory() {
override protected def createDefaultJSch(fs: FS): JSch = {
val defaultJSch = super.createDefaultJSch(fs)
defaultJSch.removeAllIdentity()
defaultJSch.addIdentity(new File("/home/xw/.ssh/id_rsa").getAbsolutePath)
defaultJSch.setKnownHosts("/home/xw/.ssh/known_hosts")
val configRepository:ConfigRepository = com.jcraft.jsch.OpenSSHConfig.parseFile("/home/xw/.ssh/config")
defaultJSch.setConfigRepository(configRepository)
defaultJSch
}
override protected def configure(host:OpenSshConfig.Host, session:Session ) {
// This still checks existing host keys and will disable "unsafe" authentication mechanisms
// …Run Code Online (Sandbox Code Playgroud) 我试图通过它克隆一个Git存储库CloneCommand.有了这段代码
`Git.cloneRepository().setDirectory(new File(path)).setURI(url).call();`
Run Code Online (Sandbox Code Playgroud)
远程存储库位于使用自签名证书的GitBlit实例上.由于这些自签名证书,我在克隆的获取部分执行时得到以下异常:
Caused by: java.security.cert.CertificateException: No name matching <hostName> found
at sun.security.util.HostnameChecker.matchDNS(HostnameChecker.java:221)
at sun.security.util.HostnameChecker.match(HostnameChecker.java:95)
Run Code Online (Sandbox Code Playgroud)
虽然我可以创建一个新的TrustManager,但是注册一个虚拟对象HostnameVerifier并SSLContext使用这个虚拟对象创建和初始化TrustManager.克隆完成后,还原所有这些.
但是,这意味着在同一时间启动的任何其他SSL连接都会将它们暴露给不安全的连接.
在已经克隆的仓库中,您可以将http.sslVerify设置为false,并且JGit可以正常工作.
是否有一种更清晰的方式,我可以告诉JGit将此http.sslVerify设置为false以进行克隆操作,就像我可以为已经克隆的回购做的那样.