Reputation: 5084
I am using JGit to access a local repository using Java. I need to access the changed files of a repository which is typically executed using the git status
command in git. What is the JGit implementation for this command?
So basically I need the JGit representation of a typical:
git status
My current implementation:
private void initRepository(String path){
try {
File workTree = new File(path);
Git git = Git.open(workTree);
//I need to get all the modified/changed files here
} catch (IOException ex) {
//handle exception
}
}
Upvotes: 3
Views: 576
Reputation: 1015
The equivalent of a git status
command can be run as follows
Status status = git.status().call();
With the various bits of information then being retrieved from the status object:
System.out.println("Added: " + status.getAdded());
System.out.println("Changed: " + status.getChanged());
System.out.println("Conflicting: " + status.getConflicting());
System.out.println("ConflictingStageState: " + status.getConflictingStageState());
System.out.println("IgnoredNotInIndex: " + status.getIgnoredNotInIndex());
System.out.println("Missing: " + status.getMissing());
System.out.println("Modified: " + status.getModified());
System.out.println("Removed: " + status.getRemoved());
System.out.println("Untracked: " + status.getUntracked());
System.out.println("UntrackedFolders: " + status.getUntrackedFolders());
Source: JGit Cookbook
Upvotes: 3