jgit

JGit how do i get the SHA1 from a RevCommit?

你说的曾经没有我的故事 提交于 2019-12-04 00:18:10
This seems like an idiotic question, but I can't find documentation on it anywhere. How do I get a the SHA1 of a RevCommit object? RevCommit inherits from AnyObjectId which has a getName function. getName public final String getName() Returns : string form of the SHA-1, in lower case hexadecimal. 来源: https://stackoverflow.com/questions/22276456/jgit-how-do-i-get-the-sha1-from-a-revcommit

Use JGit TreeWalk to list files and folders

穿精又带淫゛_ 提交于 2019-12-03 23:45:20
I'd like to use JGit to display a list of all files and folders for the head revision. I'm able to list all files using TreeWalk, but this does not list folders. Here is what I have so far: public class MainClass { public static void main(String[] args) throws IOException { FileRepositoryBuilder builder = new FileRepositoryBuilder(); Repository repository = builder .setGitDir(new File("C:\\temp\\git\\.git")).readEnvironment() .findGitDir().build(); listRepositoryContents(repository); repository.close(); } private static void listRepositoryContents(Repository repository) throws IOException {

Java git client using jgit

守給你的承諾、 提交于 2019-12-03 07:00:20
I am having some difficulties with a git client written in java. I am using the jGit library to connect through ssh on the git server. The problem is that i don't know how to specify the path to the private key and the passphrase for it. I couldn't find any examples in the jGit documentation about what functions i need to call. From what i read the jGit library is using JSch to connect to the server using ssh and JSch supports private keys and passphrases. Does anyone have any experience with this or has some working code? Thank you I didn't ever use jGit, but from looking at the Javadocs

How do you set the configuration for jschconfigsessionfactory for jgit so that pull and push work?

落爺英雄遲暮 提交于 2019-12-03 03:01:45
I am trying to do a git pull/push using jgit's api with the following code org.eclipse.jgit.api.Git.open(theRepoFile).pull().call() but I am getting exceptions JSchException Auth fail com.jcraft.jsch.Session.connect (Session.java:461) org.eclipse.jgit.transport.JschConfigSessionFactory.getSession (JschConfigSessionFactory.java:116) org.eclipse.jgit.transport.SshTransport.getSession (SshTransport.java:121) org.eclipse.jgit.transport.TransportGitSsh$SshPushConnection.<init> (TransportGitSsh.java:306) org.eclipse.jgit.transport.TransportGitSsh.openPush (TransportGitSsh.java:152) org.eclipse.jgit

How to hard reset from one git branch to other in JGit?

[亡魂溺海] 提交于 2019-12-02 05:23:08
问题 I have two branches one is master and another one level1. Now level1 is the latest I need to hard reset master to level1 normally in git bash I can do that by following command. $ git checkout master $ git tag old-master-branch $ git reset --hard level1 $ git merge -s ours origin/master $ git push origin master This one works fine for me. My question is how can I achieve it by using JGit. I have tried it. But I am not able to figure out how to set the source and target branch. consider a

How to hard reset from one git branch to other in JGit?

痴心易碎 提交于 2019-12-02 02:52:06
I have two branches one is master and another one level1. Now level1 is the latest I need to hard reset master to level1 normally in git bash I can do that by following command. $ git checkout master $ git tag old-master-branch $ git reset --hard level1 $ git merge -s ours origin/master $ git push origin master This one works fine for me. My question is how can I achieve it by using JGit. I have tried it. But I am not able to figure out how to set the source and target branch. consider a scenario I have cloned a master branch Git git = Git.cloneRepository().setURI(remote)

What's the jgit equivalent for “git merge-base --fork-point branchA branchB”

寵の児 提交于 2019-12-02 02:13:48
问题 What's the jgit equivalent codeo for "git merge-base --fork-point branchA branchB"? I tried the code below but I'm not getting the correct answer. I'm using this to hunt for branch origin. foreach.branch (git merge-base --fork-point mybranch theirbranch) will yield null a commit id only for point of origin. So, all I need to do is to figure out how to do this in jgit and I have a method for calculating branch origin when I don't already know it. private String getMergeBase(Repository

Do GitHub and GitLab support git clone's --filter parameter?

家住魔仙堡 提交于 2019-12-01 21:52:24
I want to use git's partialClone feature. In this answer I saw the git clone --filter=tree:none <repo> command. But when trying to execute on github, the prompt warning: filtering not recognized by server, ignoring . It did not work. I want to know if it is not supported by the GitHub website, or if there is a problem with my settings. I asked the feedback staff of GitHub and have not got the answer from the technician. This almost certainly isn't supported by GitHub or GitLab yet. The --filter option is under active development and isn't really ready for general-purpose consumption yet.

How do I rename a file in JGit

大憨熊 提交于 2019-12-01 21:33:48
How do I rename a file in JGit. That is, given a working file named file1. The command line would be: git mv file1 file2 There is no direct equivalent to git mv in Git. git mv is just a short hand for mv oldname newname git add newname git rm oldname (see here) Respectively, use File.renameTo() or, since Java 7, Files.move() to move the file and then git.add().addFilepattern( "newname" ).call(); git.rm().addFilepattern( "oldname" ).call(); to update the Git index. The paths given to addFilePattern() must be relative to the work directory and path segments must always be separated by slashes (

How to write git log --stat command in JGit

自闭症网瘾萝莉.ら 提交于 2019-12-01 19:43:51
I have following git command: git log --stat=1000 --all > gitstat.log Is it possible to achieve this in JGit? If yes, what is the equivalent way to write this in JGit? To access the history of a repository, JGit provides the RevWalk . Its markStart() method is used to specify at which commits the history should start. All refs in a repository can be obtained with Repository::getAllRefs() . Once a RevWalk instance is set up, use its iterator or its next() method to traverse the history. Putting that together would look like this: try (RevWalk revWalk = new RevWalk(repository)) { for (Ref ref :