jgit

JGit clone repository

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-29 19:25:51
问题 I'm trying to clone Git repository with JGit and I have problem with UnsupportedCredentialItem. My code: FileRepositoryBuilder builder = new FileRepositoryBuilder(); Repository repository = builder.setGitDir(PATH).readEnvironment().findGitDir().build(); Git git = new Git(repository); CloneCommand clone = git.cloneRepository(); clone.setBare(false); clone.setCloneAllBranches(true); clone.setDirectory(PATH).setURI(url); UsernamePasswordCredentialsProvider user = new

jGit - how to add all files to staging area

北战南征 提交于 2019-11-29 16:59:09
问题 I tried in a lot of ways to clone a repo with jGit (it works). Then, I write some archive in the repository, and tried to add all (a git add * , git add -A or something like it).. but it don't work. The files simple are not added to the staging area. My code is like this: FileRepositoryBuilder builder = new FileRepositoryBuilder(); Repository repository = builder.setGitDir(new File(folder)) .readEnvironment().findGitDir().setup().build(); CloneCommand clone = Git.cloneRepository(); clone

How to obtain the RevCommit or ObjectId from a SHA1 ID string with JGit?

跟風遠走 提交于 2019-11-29 13:32:51
This question is the inverse of this question: JGit how do i get the SHA1 from a RevCommit? . If I am given the SHA1 ID of a particular commit as a string, how can I obtain the ObjectId or associated RevCommit in JGit? Here is a possible answer, which iterates through all RevCommit s: RevCommit findCommit(String SHAId) { Iterable<RevCommit> commits = git_.log().call(); for (RevCommit commit: commits) { if (commit.getName().equals(SHAId)) return commit; } return null; } Is there anything better than this implementation above? It is probably easier to first convert the string into an ObjectId

USERAUTH fail using JGit to access git repo securely for PullCommand()

孤街浪徒 提交于 2019-11-29 12:54:26
I am trying to do a git pull using JGit's API with the following code public class gitHubTest { JSch jsch = new JSch(); // Defining the private key file location explicitly String userHome = System.getProperty("user.home"); String privateKey = userHome + "/.ssh/id_rsa"; String knownHostsFile = userHome + "/.ssh/known_hosts"; Repository localRepo = new FileRepository("/LocalPath/.git"); public gitHubTest() throws Exception { jsch.setConfig("StrictHostKeyChecking", "no"); jsch.setKnownHosts(knownHostsFile); jsch.addIdentity(privateKey); System.out.println("privateKey :" + privateKey); Git git =

Abort merge using JGit

我的梦境 提交于 2019-11-29 11:08:24
This is pretty straightforward: How do I simulate the command git merge --abort in JGit? I need to "preview" the conflicts prior to the real merge There is no direct equivalent for git merge --abort in JGit. This code snippet may serve as a starting point: // clear the merge state repository.writeMergeCommitMsg( null ); repository.writeMergeHeads( null ); // reset the index and work directory to HEAD Git.wrap( repository ).reset().setMode( ResetType.HARD ).call(); It empties the merge state files and then resets index and work directory to the contents of the current HEAD commit. In order to

How to get the file list for a commit with JGit

你离开我真会死。 提交于 2019-11-29 09:35:12
I have been working on a Java based product for which the Git features are going to be integrated. Using one of the Git features, I have done adding 10+ files into the Git repository by staging followed by committing them in a single commit. Is the reverse of the above process possible? I.e Finding the list of files committed as part of a commit. I got the commit with the help of the git.log() command but I am not sure how to get the file list for the commit. Example Code: Git git = (...); Iterable<RevCommit> logs = git.log().call(); for(RevCommit commit : logs) { String commitID = commit

List of files changed between commits with JGit

半世苍凉 提交于 2019-11-29 08:13:29
I'd like to get the paths of the files changed (added, modified, or deleted) between two commits. From the command line, I'd simply write git diff --name-only abc123..def456 What is the equivalent way to do this with JGit? You can use the DiffFormatter to get a list of DiffEntry s. Each entry has a changeType that specifies whether a file was added, removed or changed. An Entry s' getOldPath() and getNewPath() methods return the path name. The JavaDoc lists what each method retuns for a given change type. ObjectReader reader = git.getRepository().newObjectReader(); CanonicalTreeParser

JGit: Checkout a remote branch

僤鯓⒐⒋嵵緔 提交于 2019-11-29 05:33:29
I'm using JGit to checkout a remote tracking branch. Git binrepository = cloneCmd.call() CheckoutCommand checkoutCmd = binrepository.checkout(); checkoutCmd.setName( "origin/" + branchName); checkoutCmd.setUpstreamMode(CreateBranchCommand.SetupUpstreamMode.TRACK ); checkoutCmd.setStartPoint( "origin/" + branchName ); Ref ref = checkoutCmd.call(); The files are checked out, but the HEAD is not pointing to the branch. Following is the git status output, $ git status # Not currently on any branch. nothing to commit (working directory clean) The same operation can be performed in git command line,

记录SpringCloud使用的一些问题

左心房为你撑大大i 提交于 2019-11-28 20:15:33
一、服务下线延迟问题 这个虽然是为了更好的高可用,但是下线服务依然存留很长一段时间(默认下最长有2分钟),不利于集群环境部署。 解决办法: 去除保护机制,修改默认的配置,使服务尽快被去除。可看这里。 二、配置中心的git账号问题 配置中心可以使用git统一管理配置,配置git账号如果填自己的就会泄露自己密码。使用密码加密也是不可行的,因为也会被解密。 解决办法: 使用ssh登陆,springcloud config server使用JGit从git获取资源,JGit支持ssh登陆。 如果生成密钥设置了passphrase,在配置加上passphrase:id_rsa的通行码即可。 三、eureka prod环境注册的权限问题 怎么对注册prod环境做限制?万一不小心启动了prod岂不是很危险。 解决办法:暂没想到~ 四、对springcloud的认识 使用起来很方便,简单的配置就可以跑起来一套微服务架构。 而且现在还处在快速更新阶段,最新的F版本全部支持sb2.0,是个更新很大的版本,以后肯定会更强大。 组件很多,一般企业分布式开发所需要的功能都可以使用springcloud实现。 如果将就,那完全使用springcloud全家桶。 如果讲究,那肯定是不行的,springcloud帮我们实现了很多,很多默认配置,拓展起来有时候很不方便。 所以,实际应该还是,视情况而定

Why is not recommended to have an Eclipse project folder as a Git repository?

岁酱吖の 提交于 2019-11-28 19:03:09
问题 When sharing a project as git and trying to make the Eclipse project folder as the git repository, Eclipse says that it is not recommended to do so and that it should be outside the Eclipse workspace. Why is that? 回答1: From Eclipse EGit help pages, It is probably not a good idea to make a project the root folder of your Repository The reason is that you will never be able to add another project to this Repository, as the .project file will occupy the root folder; you could still add projects