jgit

Get the list of changed files after a pull with JGit

自作多情 提交于 2019-12-10 20:28:31
问题 I would like to know how I can retrieve the list of changed files after a pull request. I'm using this to get all the merged commits, but I want to know all the changed files. Git git = new Git(localRepo); PullCommand pullCmd = git.pull(); PullResult pullResult = pullCmd.call(); MergeResult mergeResult = pullResult.getMergeResult(); ObjectId[] mergedCommits = mergeResult.getMergedCommits(); for (ObjectId mergedCommit : mergedCommits) { // And now? } 回答1: Building on the previous comments

JGit Java Git Library Unstaging Files

一曲冷凌霜 提交于 2019-12-10 17:35:38
问题 I can't get reset to work properly in JGit. Ie. i can add all files to the index, and i can remove/reset/unstage some of them from the index via the command below but it doesn't work for all files. What is the proper way to unstage files in JGit? repository.getIndex().remove(getWorkignDirectoryAsFile(), new File(getWorkignDirectoryAsFile(), fileName)); repository.getIndex().write(); Also 回答1: You can remove a file from the index using JGit ResetCommand class: ResetCommand reset = new Git

IAM configuration to access jgit on S3

坚强是说给别人听的谎言 提交于 2019-12-10 14:23:47
问题 I am trying to create IAM permissions so jgit can access a directory in one of my buckets. { "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": ["s3:ListBucket"], "Resource": ["arn:aws:s3:::<mybucket>/<mydir>/*"] }, { "Effect": "Allow", "Action": [ "s3:PutObject", "s3:GetObject", "s3:DeleteObject" ], "Resource": ["arn:aws:s3:::<mybucket>/<mydir>"] } ] } Unfortunately it throws an error. I am not sure what other allow actions need to happen for this to work. (A little new

Does JGit support Git Credentials?

别来无恙 提交于 2019-12-10 13:59:37
问题 Does JGit support Git Credentials as documented here: http://git-scm.com/docs/gitcredentials? I haven't found yet anything to this topic. 回答1: The counterpart to Git Credentials in JGit is the CredentialsProvider interface. All commands that establish connections to remote repositories can be configured with a CredentialsProvider instance. They inherit from TransportCommand which has a setCredentialsProvider method. 来源: https://stackoverflow.com/questions/23173250/does-jgit-support-git

JGit - How to reuse the DiffFormatter

China☆狼群 提交于 2019-12-10 13:18:28
问题 It's a followup question of jgit - git diff based on file extension. I am trying to add the formatted diff to List<String> but If I try to use same DiffFormatter as below then previous entries getting appended to the next one. List<String> changes = new LinkedList<>(); try (OutputStream outputStream = new ByteArrayOutputStream(); DiffFormatter diffFormatter = new DiffFormatter(outputStream)) { diffFormatter.setRepository(git1.getRepository()); TreeFilter treeFilter = PathSuffixFilter.create("

Usage of 'pull' command in Jgit

六眼飞鱼酱① 提交于 2019-12-10 12:59:00
问题 I'm a new user of git and am using JGit to interact with a remote git repository. In JGit, I used CloneCommand to initially to clone a repo, and it worked without a issue. However, when I try to use PullCommand , which is the equivalent of SVN update AFAIK, the local repo contents are not updated. This is the code that I used: private String localPath; private Repository localRepo; private Git git; localPath = "/home/test/git_repo_test"; remotePath = "https://github.com/test/repo_1.git"; try

Use JGit TreeWalk to list files and folders

孤街醉人 提交于 2019-12-09 14:25:44
问题 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);

How do I rename a file in JGit

孤人 提交于 2019-12-09 03:39:06
问题 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 回答1: 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

Egit is installed (came with Juno), but does not show at all

扶醉桌前 提交于 2019-12-09 03:32:29
问题 I want to use GIT in eclipse, and preferably EGit, for it's support from the eclipse community itself. However, despite eclipse claiming the required plugins are installed, it does not appear in the perspectives, import and settings menu's. I am using Eclipse Juno for Java EE, and have confirmed the following installs: When I update software, there are no more updates available. When I go to the repository for Egit, or JGit for that matter, eclipse tells me the plugins are already installed.

Getting all branches with JGit

拟墨画扇 提交于 2019-12-08 16:23:27
问题 How can I get all branches in a repository with JGit? Let's take an example repository. As we can see, it has 5 branches. Here I found this example: int c = 0; List<Ref> call = new Git(repository).branchList().call(); for (Ref ref : call) { System.out.println("Branch: " + ref + " " + ref.getName() + " " + ref.getObjectId().getName()); c++; } System.out.println("Number of branches: " + c); But all I get is this: Branch: Ref[refs/heads/master=d766675da9e6bf72f09f320a92b48fa529ffefdc] refs/heads